如何绑定动态创建的扩展器的isexpanded属性 [英] How do I bind the isexpanded property of dynamically created expanders

查看:123
本文介绍了如何绑定动态创建的扩展器的isexpanded属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这是我的第一个条目,所以请耐心等待。

我的问题是我在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 IsExpanded 属性的绑定,如下所示,

Hi, just change the binding of IsExpanded property of Expander like below,
<Expander x:Name="Exp" IsExpanded="{Binding FilterExpander, Mode=TwoWay}">
   <Expander.Header>
      <TextBlock Text="{Binding Name}" Foreground="White"/>
   </Expander.Header>
<ItemsPresenter/>
</Expander>


我发现了问题。 View没有找到Property FilterExpander。问题是,Expander查看了Property的ViewCollection。我不得不改变绑定:



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.


这篇关于如何绑定动态创建的扩展器的isexpanded属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆