简体   繁体   English

如何仅动态扩展单击的扩展器?

[英]How do I dynamically expand only the clicked expander?

I have a problem with my expander. 我的扩展器有问题。 (again...) (再次...)

I have a DataGrid with an unknown number of entry's. 我有一个数据网格,其条目数未知。 Each Entry is different and added manually. 每个条目都是不同的,并手动添加。 Each of them has a specific "Area" they belongs to. 他们每个人都有他们所属的特定“区域”。 The entry's are grouped through the "Area". 条目通过“区域”进行分组。 The Grouping is carried out with a GroupItem. 分组是通过GroupItem进行的。 Within this GroupItem there is an Expander, with an IsExpanded Binding. 在此GroupItem中,有一个具有IsExpanded绑定的Expander。 I also have a filter TextBox where the entry's are filtered and only the correct one's are shown in the Groups. 我还有一个过滤器TextBox,其中对条目进行了过滤,并且组中仅显示了正确的条目。 If the filter finds an entry, than the isExpanded Property of all Expanders should be true. 如果过滤器找到一个条目,则所有扩展器的isExpanded属性都应该为true。 If the filter doesn't find an entry, than the isexpanded is false. 如果过滤器找不到条目,​​则isexpanded为false。 The problem in this solution is: If I click on one Expander, all Expanders isExpanded Property is set to true, but it should only be the one I clicked. 此解决方案中的问题是:如果单击一个Expander,则所有Expanders isExpanded属性都将设置为true,但它只能是我单击的那个。

I know this bevahiour is because I only have 1 Expander which is created multiple times. 我知道这是因为我只有1个膨胀器,它被多次创建。

Now to the question: Is it possible that only the expander I click is opened and if the Filter finds a value, all expanders are opened? 现在要问的问题:是否可能仅打开我单击的扩展器,并且如果过滤器找到一个值,则所有扩展器都将打开?

This is the Property: 这是属性:

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

This is the Headerstyle where the Expander is: 这是Expander所在的Headerstyle:

<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>

I hope this is possible and someone can help me. 我希望这是可能的,有人可以帮助我。

Thanks in advance 提前致谢

I found a solution. 我找到了解决方案。 I only had to set the Expander mode to "OneWay". 我只需要将扩展​​器模式设置为“ OneWay”。 That way it works fine. 这样就可以正常工作。 This 这个

<expander x:name="Exp" isexpanded="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},Mode=FindAncestor},Path=DataContext.FilterExpander}"</expander>

Should be 应该

<expander x:name="Exp" isexpanded="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},Mode=FindAncestor},Path=DataContext.FilterExpander, Mode=OneWay}"</expander>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM