Strange behaviour of CheckBox and TwoWay bound property
Posted
by walkor
on Stack Overflow
See other posts from Stack Overflow
or by walkor
Published on 2010-06-07T16:38:46Z
Indexed on
2010/06/07
16:42 UTC
Read the original article
Hit count: 234
Silverlight
|databinding
Hello, everyone. I fell in the following situation: I have a main UserControl with a DataGrid (which contains List). I need to show different panels depending on properties of the selected row(object). So i've created 2 controls and included them into this main control. Main control has 2 public properties -
public List<ComplexObject> SourceList { get; set; }
and
public ComplexObject CurrentObject { get; set; }
Pseudo-code:
<UserControl x:Name="Main">
<DataGrid ItemsSource="{Binding SourceList}" SelectedItem="{Binding CurrentObject, Mode=TwoWay}"/>
<Controls:RightPanelFirst Visibility="condition2"/>
<Controls:RightPanelSecond Visibility="condition2"/>
</UserControl>
RightPanelFirst and RightPanelSecond have the following xaml:
<UserControl>
<... content here...>
<CheckBox IsChecked="{Binding CurrentObject.ComplexProperty.SimpleProperty1, Mode=TwoWay}">
<CheckBox IsChecked="{Binding CurrentObject.ComplexProperty.SimpleProperty2, Mode=TwoWay}" x:Name="cbSecond">
<TextBox IsEnabled="{Binding IsChecked, ElementName=cbSecond}"/>
</UserControl>
So, my actual steps:
- Check both checkboxes (object values are set to true)
- Make other actions in code behind which modify CurrentObject.
- Then i want UI to reflect the changes, so I call NotifyPropertyChanged("CurrentObject");
- SimpleProperty1 remains the same, but SimpleProperty2 resets to false
I have no idea why this happens, can anyone help me please? Silverlight drives me mad.
© Stack Overflow or respective owner