2012-02-01 125 views

回答

0

我发现它...我可以在我的用户定义DependensyProperty typof RelayCommand和我DependensyProperty绑定到我的视图模型命令

1

是的,您可以将routed event添加到您按下按钮时调用的用户控件。

然后,您可以使用各种技术在用户控件事件触发时调用视图模型动词。

E.g.你可以使用attached property,或者我会推荐使用MVVM框架,如Caliburn.Micro,它具有Actions,这使得它更直接。

0

我真的不知道你的意思,但我采取了一枪。

在后面的代码,定义一个RoutedCommand

public partial class MyUserControl : UserControl 
{ 
    public static RoutedCommand Click = 
     new RoutedCommand("Click", typeof(UserControl)); 
} 

然后,它的XAML,建立一个命令结合:

<UserControl.CommandBindings> 
    <CommandBinding 
     Command="{x:Static MyNameSpace:MyUserControl.Click}" 
     CanExecute="ClickCanExecute" 
     Executed="ClickExecuted"/> 
</UserControl.CommandBindings> 

然后在后面的代码添加处理程序

private void ClickCanExecute(object sender, CanExecuteRoutedEventArgs e) 
{ 
    e.CanExecute = true; 
} 

private void ClickExecuted(object sender, ExecutedRoutedEventArgs e) 
{ 
    // TODO execution logic goes here 
} 

我关闭了吗? :)

相关问题