WPF - expander Collapsed event being triggered by child controls with validation

Posted by Shaboboo on Stack Overflow See other posts from Stack Overflow or by Shaboboo
Published on 2010-04-30T16:13:18Z Indexed on 2010/04/30 16:17 UTC
Read the original article Hit count: 443

Filed under:
|
|
|
|

I have an expander that contains an ItemsControl. The items in the itemsControl are templated, some have textboxes in them, others have checkboxes. Both have bindings that cause validation. The styling and validation is working as expected.

The problem is when I first expand the expander and cause a change to either control, the expander collapses again, this is not what I want. If I repeat this a second time this does not happen.

I'm not sure what is triggering this strange behaviour. I've tried setting the focus to the itemsControl when the expander expands with no luck. What is differnt the second time it's expanded? Could it be the validation? Any Ideas?

XAML:

<Expander Header="{Binding SubSectionName}" Padding="0" >
    <ItemsControl ItemsSource="{Binding ConfigSubSectionSettings}" 
     ItemTemplateSelector="{StaticResource Settings_Selector}" />
</Expander>

<!-- Templates selected by the ItemTemplateSelector -->

<DataTemplate x:Key="subSection_Bool">
    <StackPanel Orientation="Horizontal">
        <TextBlock x:Name="lbl" Text="{Binding SubSectionName}" >
        <CheckBox x:Name="chk" IsChecked="{Binding BoolValue, ValidatesOnDataErrors=True}"
              VerticalAlignment="Center" Margin="2"  >
    </StackPanel >
</DataTemplate>

<DataTemplate x:Key="subSection_Text">
    <StackPanel Orientation="Horizontal">
        <TextBlock x:Name="lbl" Text="{Binding SubSectionName}" />
        <TextBox x:Name="txt"  VerticalAlignment="Center"  
                 Text="{Binding StringValue, ValidatesOnDataErrors=True}" />
    </StackPanel>
</DataTemplate>

© Stack Overflow or respective owner

Related posts about wpf

Related posts about events