0

I have an ObservableCollection of SettingsModel has a string and bool. Now i'm making settings page, with listbox of switches.

<Grid>
                <ListBox 
                         HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                         Margin="0,0,0,0" 
                         ItemsSource="{Binding Path=SettingsItems, Mode=TwoWay}" 
                         ItemContainerStyle="{StaticResource ListBoxItemsStrerchedStyle}" >
               <ListBox.ItemTemplate> 
                   <DataTemplate> 
                       <toolkit:ToggleSwitch 
                           Header="{Binding kind}" 
                           Content="{Binding value}" 
                           IsChecked="{Binding value, Mode=TwoWay}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>

The problem is that when user changes state of the switch, it is not rising notification (Content is not changed). Moreover, if to scroll down through the list (about 30 items) and then scroll up, some of the switches are changing their state.

Should i use ObservableDictionary (which is looking quite obsolete), or make SettingsModel throw notification somehow?

Vitalii Vasylenko
  • 4,776
  • 5
  • 40
  • 64
  • 1
    Is SettingsModel your class? If so, you may need to implement INotifyPropertyChanged. If not, you may want to consider writing your own class that does (and mirror the properties you need but with notification). http://stackoverflow.com/questions/1039505/inotifypropertychanged-wpf – Fise Apr 22 '13 at 13:55
  • @Fise yep, it was needed just to send notifications from the model. Though, i still dont know, why state of switches were changed by themself. – Vitalii Vasylenko Apr 22 '13 at 14:56

1 Answers1

2

Just in case, anyone else would face the same problem, here is the sample, using mvvm light.

public class SettingsModel : ViewModelBase
{
    private bool _value;
    public bool Value
    {
        get { return _value; }
        set { Set(() => Value, ref _value, value); }
    }

    private string _kind;
    public string Kind
    {
        get { return _kind; }
        set { Set(() => Kind, ref _kind, value); }
    }
}
Vitalii Vasylenko
  • 4,776
  • 5
  • 40
  • 64