我有一个自定义按钮控件,它的ICommand属性配置为依赖属性,如下所示:
public partial class SpecialButton : UserControl
{
public static readonly DependencyProperty s_buttonCommand =
DependencyProperty.Register(nameof(ButtonCommand), typeof(ICommand), typeof(SpecialButton), new PropertyMetadata(null, _ButtonCommandChanged));
public ICommand ButtonCommand
{
get { return (ICommand)GetValue(s_buttonCommand); }
set { SetValue(s_buttonCommand, value); }
}
}
每当我在xaml中创建按钮的实例时,我都会在VisualStudio中的设计器中得到以下错误:
无法在“Common_WPF_SpecialButton_12_635476180”类型的“ButtonCommand”属性上设置“Binding”。只能在DependencyObject的DependencyProperty上设置“Binding”。
当你真正运行代码时,它编译得很好,而且工作得很完美,但设计器中的这个错误很烦人,我不知道如何消除它。我已经检查了依赖属性注册中的名称和类型,我不认为是这样。此外,该控件具有的背景颜色等其他属性都可以正常工作,并且它们的依赖属性注册看起来完全相同。
非常感谢您的帮助!