WPF CheckBox TwoWay Binding not working
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