I have
<DataGridCheckBoxColumn
Binding="{Binding Path=Foo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
/>
And
public bool Foo{ get; set; }
Checking/Unchecking sets Foo
, but setting Foo
in code does not change the Checkbox state. Any Suggesitons?
You need to raise the PropertyChanged
event when you set Foo in your DataContext
. Normally, it would look something like:
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));
}
}
}
If you call Foo = someNewvalue
, the PropertyChanged
event will be raised and your UI should be updated
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With