0
votes

this is my first entry, so please be patient with me. My problem is that i have Expanders inside a DataGrid. The Expanders are used for Grouping. I also have a filter textfield which filters the View and shows only the matching lines. My problem is: the Grouping expanders isexpanded property should be true when the search finds entries and false if the search is not used. This is my DataGrid.GroupStyle:

<DataGrid.GroupStyle>
  <GroupStyle ContainerStyle="{StaticResource GroupHeaderSettingsStyle}">
         <GroupStyle.Panel>
              <ItemsPanelTemplate>
                   <DataGridRowsPresenter/>
              </ItemsPanelTemplate>
         </GroupStyle.Panel>
  </GroupStyle>
</DataGrid.GroupStyle>

This is the StaticResource

<Style x:Key="GroupHeaderSettingsStyle" TargetType="{x:Type GroupItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type GroupItem}">
                        <Expander x:Name="Exp" IsExpanded="{Binding Path=FilterExpander,Mode=TwoWay}">
                            <Expander.Header>
                                <TextBlock Text="{Binding Name}" Foreground="White"/>
                            </Expander.Header>
                            <ItemsPresenter/>
                        </Expander>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

And this is my C# Property:

public bool? FilterExpander
    {
        get
        {
            return _FilterExpander;
        }
        set
        {
            _FilterExpander = value;
            RaisePropertyChanged(() => FilterExpander);
        }
    }

It never gets into the "get-method", so I think the problem is within the xaml Code. But I am not sure.

I hope you can help me. If I forgot some Code Snippets or information please let me know.

Thanks

What I have tried:

All "modes" All UpdateSourceTriggers, Also RelativeSource Binding

1
It's happens probably because FilterExpander property is not the part of the GroupItem DataContext. You can try to move it into class that represents GroupItems of DataGrid (that contains Name property).bars222
And maybe this can help you stackoverflow.com/questions/6099141/…bars222
Thanks for your reply. The FilterExpander Property is in the DataContext class and the link didn't help either :( But thanks anywayEvosoul

1 Answers

0
votes

I found the problem. The View didn't find the Property FilterExpander. The Problem was, that Expander looked inside the ViewCollection for the Property. I had to change the binding to this:

<Style x:Key="GroupHeaderSettingsStyle" TargetType="{x:Type GroupItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type GroupItem}">
                        <Expander x:Name="Exp" IsExpanded="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},Mode=FindAncestor},Path=DataContext.FilterExpander}">
                            <Expander.Header>
                                <TextBlock Text="{Binding Name}" Foreground="White"/>
                            </Expander.Header>
                            <ItemsPresenter/>
                        </Expander>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Now it works correctly.