Hello,
I am working on an MVVM application.I have in view a ListBox which is bound to an ObservableDictionary in VM as follows:
C# VM:
private ObservableDictionary<string, bool> mCategories;
public ObservableDictionary<string, bool> Categories
{
get { return mCategories; }
set { mCategories = value; FirePropertyChanged("Categories"); }
}
Categories = new ObservableDictionary<string, bool>()
{
{ "Allgemein", true},
{ "Dampf", false},
{ "Fernwärme", false},
{ "Prozessabhängig", false},
{ "Stromverbrauch", false}
};
XAML VIEW:
<telerik:RadListBox ItemsSource="{Binding Categories}">
<telerik:RadListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding Value, Mode=TwoWay}"/>
<TextBlock Text="{Binding Key, Mode=OneWay}"/>
</StackPanel>
</DataTemplate>
</telerik:RadListBox.ItemTemplate>
</telerik:RadListBox>
I have the following problem: Binding seems not to work in the direction View to VM, that when I check a Checkbox the Value of the corresponding dictionary element will not be set to true, while it works in the other direction (VM to View) that when I set the Value of a dictionary elemnt in C# code (VM) the CheckBx is checked in View.
Any suggestion?
Thanks
I am working on an MVVM application.I have in view a ListBox which is bound to an ObservableDictionary in VM as follows:
C# VM:
private ObservableDictionary<string, bool> mCategories;
public ObservableDictionary<string, bool> Categories
{
get { return mCategories; }
set { mCategories = value; FirePropertyChanged("Categories"); }
}
Categories = new ObservableDictionary<string, bool>()
{
{ "Allgemein", true},
{ "Dampf", false},
{ "Fernwärme", false},
{ "Prozessabhängig", false},
{ "Stromverbrauch", false}
};
XAML VIEW:
<telerik:RadListBox ItemsSource="{Binding Categories}">
<telerik:RadListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding Value, Mode=TwoWay}"/>
<TextBlock Text="{Binding Key, Mode=OneWay}"/>
</StackPanel>
</DataTemplate>
</telerik:RadListBox.ItemTemplate>
</telerik:RadListBox>
I have the following problem: Binding seems not to work in the direction View to VM, that when I check a Checkbox the Value of the corresponding dictionary element will not be set to true, while it works in the other direction (VM to View) that when I set the Value of a dictionary elemnt in C# code (VM) the CheckBx is checked in View.
Any suggestion?
Thanks