我有一个按钮条用户控件,我想在我的大多数表单上使用它。
我添加了如下命令......
public ICommand Create
{
get
{
return buttonCreate.Command;
}
set
{
buttonCreate.Command = value;
}
}
我已将它们设置为依赖属性,以便我可以绑定到它们......
public static readonly DependencyProperty CreateCommandProperty =
DependencyProperty.Register(
"Create",
typeof(ICommand),
typeof(StandardButtonStrip),
new PropertyMetadata((ICommand)null));
然后我将我的用户控件绑定到命令......
<commoncontrols:StandardButtonStrip HorizontalAlignment="Stretch" Create="{Binding CreateCommand}" />
我正在设置命令如下......
_viewModel.CreateCommand = new DelegateCommand<object>(OnCreateCommand, CanCreate);
但尽管事实上我总是在 CanCreate 方法上返回 true,但按钮被禁用......如果我在 return true 上放置一个断点,它永远不会触发!
public bool CanCreate(object parm)
{
return true;
}
我试过这个,看看它是否会刷新绑定,但没有喜悦!
_viewModel.CreateCommand.RaiseCanExecuteChanged();
我认为问题在于用户控件以及我如何将命令作为属性传递,但不确定......