我有一个这样定义的数据触发器:
<DataTrigger Binding="{Binding Path=DataContext.MyObject.MyProperty, Mode=OneWay, RelativeSource={RelativeSource AncestorType=UserControl}}" Value="False">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
MyObject 在视图模型中。现在,当 MyObject 的 MyProperty 更改时,它不会通知 UI,即使 MyProperty 确实通知 OnPropertyChange。当我们使用 Microsoft Prism 作为框架时,对象 MyObject 已在 Container 中注册。
我应该如何让它工作?
编辑: MyObject 是这样定义的:
public class MyObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
private bool _myProperty;
public bool MyProperty
{
get { return _myProperty; }
set
{
if (value == _myProperty)
return;
_myProperty = value;
OnPropertyChanged("MyProperty");
}
}
}