依赖属性ICommand在嵌套控件中不起作用

时间:2017-05-15 09:44:56

标签: c# wpf command

我有一个带DependecyProperty的UserControl:

git symbolic-ref --short HEAD 2> /dev/null || git rev-parse HEAD

在Xaml中:

public static readonly DependencyProperty OpenCommandProperty =
        DependencyProperty.Register(
            "OpenCommand",
            typeof(ICommand),
            typeof(BaseRouteFlatView),
            new UIPropertyMetadata(null));

 public ICommand OpenCommand
 {
    get { return (ICommand)GetValue(OpenCommandProperty); }
    set { SetValue(OpenCommandProperty, value); }
 }

我必须在第二个按钮中为工作命令指定什么来源?

1 个答案:

答案 0 :(得分:1)

尝试以下方法:

public UserControl()
{
    InitializeComponent();
    NameScope.SetNameScope(second, NameScope.GetNameScope(this));
}