I've ToggleButton defined like this in XAML:
<ToggleButton IsChecked="{Binding DateFi开发者_如何学Golter, ElementName=myUserControl, Mode=TwoWay}"/>
and 'DateFilter' defined like this:
public Boolean DateFilter { get; set; }
When I click the toggle-button, 'DateFilter' updates accordingly. BUT, if I modify 'DateFilter' in code, the ToggleButton doesn't update!
How can I do that?public MyClass : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = delegate {};
private Boolean _dateFilter;
public Boolean DateFilter
{
get { return _dateFilter; }
set
{
_dateFilter = value;
PropertyChanged(this, new PropertyChangedEventArgs("DateFilter");
}
}
}
Basically make that PropertyChanged
call whenever you change the _dateFilter, or just use the setter, and you'll be sorted. Setting the event handler to an empty delegate allows you to avoid null checks.
You need to add inheritance from INotifyPropertyChanged for myUserControl and send in DateFilter setter event PropertyChanged with "DateFilter" property name.
精彩评论