如何为 IsEnabled
添加自定义约定到 Caliburn.Micro控件的属性 - 类似于拥有 NameEnabled
绑定(bind)到IsEnabled
平行于 Name
绑定(bind)到Text
在文本框上。
在某种程度上,我想要实现的方式类似于 CanSave
属性可用于启用/禁用绑定(bind)到 Save
的按钮方法,但适用于所有控件。
最佳答案
您可以通过在 ViewModel 中设置 bool 属性来启用/禁用控件,并且只需绑定(bind)到 XAML 中的 IsEnabled:
TextBox Name="SerialNumber" IsEnabled="{Binding IsReadOnly}"...
ViewModel:
private bool isReadOnly;
public bool IsReadOnly
{
get { return isReadOnly; }
set
{
this.isReadOnly = value;
NotifyOfPropertyChange( () => IsReadOnly);
}
}
关于wpf - 将 IsEnabled 的约定添加到 Caliburn.Micro,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9044051/