2016-03-18 37 views
0

我想使用MetroEventToCommand库来绑定一个事件。 http://metroeventtocommand.codeplex.com/MetroEventToCommand的CommandParameter不能与控件一起使用(Windows通用10)

它调用该方法,但它不提供控件作为参数。据说它是空的。

这就是我所拥有的。

<ScrollViewer x:Name="test"> 
    <ListView/> 
    <metroEventToCommand:EventToCommandManager.Collection> 
      <metroEventToCommand:EventToCommand Command="{Binding RefreshCommand}" Event="ViewChanging" CommandParameter="{Binding ElementName=test, Mode=TwoWay}"/> 
    </metroEventToCommand:EventToCommandManager.Collection> 
    </ScrollViewer> 

    public RelayCommand<ScrollViewer> RefreshCommand { get; set; } 

    private void init() 
    { 
    RefreshCommand = new RelayCommand<ScrollViewer>(Refresh); 
    } 

    private void Refresh(ScrollViewer o) 
    { 
     if (o != null) 
     { 

     } 
    } 

在此先感谢。

+0

我会尝试将RelayCommand更改为RelayCommand ...应该让它通过,您可以检查实际发生的情况。空表示它不是通过任何东西,或者它不符合类型要求。充分披露,我之前没有使用过metroEventToCommand。 –

+0

已经尝试过,它没有工作。 – denderp

回答

0

确定...不是一个答案,但我不能把代码放在评论中。我使用MVVM Light制作了一个快速应用程序,并使用Interactivity库代替了metroToEventCommand。

我可以从挂钩的事件处理程序(当然),它传递

private void onViewChanging(object sender, ScrollViewerViewChangingEventArgs e) 
    { 
     vm.RefreshCommand.Execute(this.test); 
    } 

我也可以得到它使用Loaded事件或PointerEntered事件

<ScrollViewer x:Name="test" > 
      <Interactivity:Interaction.Behaviors> 
       <Core:EventTriggerBehavior EventName="PointerEntered"> 
        <Core:InvokeCommandAction Command="{Binding RefreshCommand, Mode=OneWay}" CommandParameter="{Binding ElementName=test}" /> 
       </Core:EventTriggerBehavior> 
      </Interactivity:Interaction.Behaviors> 
      <ListView x:Name="myList"/> 
     </ScrollViewer> 
来触发命令和参数

但是,当试图使用ViewChanging,ViewChanged时,Interactivity dll会抛出一个异常(无法将'Microsoft.Xaml.Interactions.Core.EventTriggerBehavior'类型的实例添加到'Microsoft.Xaml.Interactivity.BehaviorCollection'类型的集合中。) ,DirectManipulationComple特德等事件 - 是否使用参数。 ManipulationCompleted不会触发命令(我已经看到提示命令不能绑定到路由事件)。

所以,这个概念似乎可行 - 但只适用于某些事件类型。我很抱歉,这不是您的挑战的解决方案,但希望这是一些额外的信息来帮助您的尝试。

相关问题