0

In my class 'ScheduleViewModel' I have the following property:

private ReminderFilter filter;
public ReminderFilter Filter
{
 get { return filter; }
 set
 {
     filter = value;
     NotifyPropertyChanged("Filter");
 }
}

What I would like to do is bind to the properties of this object without needing to expose them in the View Model. I have tried the following XAML with no success:

<CheckBox IsChecked="{Binding Filter.Complete, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Content="Show Completed"></CheckBox>

Any suggestions?

Chrisjan Lodewyks
  • 1,227
  • 1
  • 13
  • 19

2 Answers2

1

I think you need two-way binding. Oneway will only update the view. If you check the checkbox, the value doesn't propagate back down to the object.

Josh
  • 10,352
  • 12
  • 58
  • 109
0

If you want to avoid exposing the property in the view model you will have to implement INotifyPropertyChanged in the ReminderFilter model.

Similar SO Discussion on Get Notified when model properties change

I know you said you would rather not expose the property in the view model but if you were against implementing INotifyPropertyChanged in the model:

    private ReminderFilter filter;
    public bool FilterComplete
    {
        get
        {
            return filter.Complete;
        }
        set
        {
            if (value == filter.Complete)
                return;
            filter.Complete = value;
            NotifyPropertyChanged("FilterComplete");
        }
    } 

xaml:

<CheckBox IsChecked="{Binding FilterComplete}" Content="Show Completed"></CheckBox>
Community
  • 1
  • 1
Pete H
  • 11
  • 1