Textbox具有Clear和GetSpellingErrors方法等。
对我来说,有可能拥有类似<TextBox Clear={binding…}/>?
我知道Clear不是一个"依赖"的东西。我正在创作一个用户控件。我可以根据需要添加DependencyProperty、DependencyObject。我只是想知道如何将一个方法绑定到VM。
PS我不需要Clear的替代方案,我知道我可以将属性设置为字符串空。
事实证明,您可以使用ICommand并像创建任何其他DependencyProperty一样创建它。
public static readonly DependencyProperty CancelCommandProperty = DependencyProperty.Register("CancelCommand", typeof(ICommand), typeof(AddressUserControl), new PropertyMetadata());
[BindableAttribute(true)]
public ICommand CancelCommand { get { return (ICommand)GetValue(CancelCommandProperty); } set { SetValue(CancelCommandProperty, value); } }
我仍然存在的唯一问题是,我显然需要它成为只读绑定。尝试
DependencyProperty.RegisterReadOnly(...)
但是ReadOnly DependencyProperty似乎有一个错误https://connect.microsoft.com/VisualStudio/feedback/details/540833/onewaytosource-binding-from-a-readonly-dependency-property