0
votes

I've ToggleButton defined like this in XAML:

<ToggleButton IsChecked="{Binding DateFilter, 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?

2
does you DataFilter rise an event from INotifyPropertyChanged? - Lukasz Madon

2 Answers

0
votes
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.

0
votes

You need to add inheritance from INotifyPropertyChanged for myUserControl and send in DateFilter setter event PropertyChanged with "DateFilter" property name.