问题描述
大家好,
这是我的第一个条目,所以请耐心等待。
我的问题是我在DataGrid中有Expanders。扩展器用于分组。我还有一个过滤器文本字段,它过滤视图并仅显示匹配的行。
我的问题是:当搜索找到条目时,分组扩展器isexpanded属性应为true,如果不使用搜索则为false 。
这是我的DataGrid.GroupStyle:
Hello everyone,
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>
这是StaticResource
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>
这是我的C#属性:
And this is my C# Property:
public bool? FilterExpander
{
get
{
return _FilterExpander;
}
set
{
_FilterExpander = value;
RaisePropertyChanged(() => FilterExpander);
}
}
它永远不会进入get-method,所以我认为问题出在xaml代码中。但我不确定。
我希望你能帮助我。
如果我忘记了一些代码片段或信息,请告诉我。
谢谢
我的尝试:
所有模式
所有UpdateSourceTriggers,
另外RelativeSource绑定
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
推荐答案
<Expander x:Name="Exp" IsExpanded="{Binding FilterExpander, Mode=TwoWay}">
<Expander.Header>
<TextBlock Text="{Binding Name}" Foreground="White"/>
</Expander.Header>
<ItemsPresenter/>
</Expander>
<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.
这篇关于如何绑定动态创建的扩展器的isexpanded属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!