要绑定到继承的按钮自定义控件上的命令属性,可以按照以下步骤进行解决:
CustomButton
的自定义控件。public class CustomButton : Button
{
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
"Command", typeof(ICommand), typeof(CustomButton), new PropertyMetadata(null));
public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
}
Command
属性绑定到按钮的Command
属性。
Command
属性来绑定命令。
在上述示例中,CustomButton
继承自Button
控件,并添加了一个名为Command
的依赖属性。在自定义控件的模板中,将按钮的Command
属性绑定到自定义控件的Command
属性。然后,在使用自定义控件的地方,可以通过Command
属性来绑定命令。
这样,就可以将命令绑定到继承的按钮自定义控件上的命令属性了。
上一篇:绑定到IPv4和IPv6本地回环
下一篇:绑定到接受字符串字面值参数的方法