10
<DataGridCheckBoxColumn
Binding="{Binding Path=Foo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
/>
而且
public bool Foo{ get; set; }
选中/取消选中设置Foo
,但在代码中设置Foo
不改变复选框状态。任何建议?
<DataGridCheckBoxColumn
Binding="{Binding Path=Foo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
/>
而且
public bool Foo{ get; set; }
选中/取消选中设置Foo
,但在代码中设置Foo
不改变复选框状态。任何建议?
当您在DataContext中设置Foo时,需要引发PropertyChanged事件。通常情况下,它看起来是这样的:
public class ViewModel : INotifyPropertyChanged
{
private bool _foo;
public bool Foo
{
get { return _foo; }
set
{
_foo = value;
OnPropertyChanged("Foo");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
var propertyChanged = PropertyChanged;
if (propertyChanged != null)
{
propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
如果你调用foo = someNewvalue,PropertyChanged事件将提高你的UI应该更新
不知道为什么你得到了下来投了反对票。我有同样的问题,这解决了它。 upvoted为您。 –