【发布时间】:2018-07-13 15:27:54
【问题描述】:
我有以下代码
Namespace WpfApplication1
{
using System.ComponentModel;
using System.Runtime.CompilerServices;
using WpfApplication1.Annotations;
using WpfApplication1.Enums;
public class MainWindowViewModel : INotifyPropertyChanged
{
private bool _isItemEnabled;
public MainWindowViewModel()
{
this.IsItemEnabled = false;
}
public event PropertyChangedEventHandler PropertyChanged;
public bool IsItemEnabled
{
get
{
return this._isItemEnabled;
}
set
{
this._isItemEnabled = value;
this.OnPropertyChanged(nameof(this.IsItemEnabled));
}
}
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
<CheckBox Grid.Row="0" Grid.Column="1" Margin="0,20"
IsChecked="{Binding Path = TimeIsEnabled, Mode=OneWay, UpdateSourceTrigger=PropertyChanged }"
DataContext="{Binding ElementName = MainWindowViewModel}">
TestIsEnabled
</CheckBox>
当我单击复选框时,位于文件后面代码上的属性 TimeIsEnabled 不会更改,并且它的断点也不会触发。我试图在视图模型中找到这个属性,但结果是一样的。请帮忙。
【问题讨论】: