如何仅动态扩展单击的扩展器? [英] How do I dynamically expand only the clicked expander?

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

问题描述

大家好,



我的扩展器有问题。 (再次......)



我有一个DataGrid,其入口数量未知。每个条目都不同,并手动添加。他们每个人都有一个特定的区域。条目通过区域分组。使用GroupItem执行分组。在这个GroupItem中有一个Expander,带有IsExpanded Binding。我还有一个过滤器TextBox,其中条目被过滤,只有正确的一个显示在组中。如果过滤器找到一个条目,则所有扩展器的isExpanded属性应为true。如果过滤器未找到条目,则isexpanded为false。

这个解决方案的问题是:如果我点击一个Expander,所有Expanders isExpanded Property都设置为true,但它应该只是我点击的那个。



我知道这个bevahiour是因为我只有1个Expander,它被多次创建。



现在问题:

是否可能只打开我点击的扩展器,如果Filter找到一个值,所有扩展器打开了吗?



这是物业:

Hello everyone,

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. Within this GroupItem there is an Expander, with an IsExpanded Binding. I also have a filter TextBox where the entry's are filtered and only the correct one's are shown in the Groups. If the filter finds an entry, than the isExpanded Property of all Expanders should be true. If the filter doesn't find an entry, than the isexpanded is 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.

I know this bevahiour is because I only have 1 Expander which is created multiple times.

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);
            }
        }





这是扩展器所在的Headerstyle:



This is the Headerstyle where the Expander is:

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





我希望这是可能的有人可以帮助我。



提前谢谢



我尝试过:



创建多个扩展器

尝试将bool数组绑定到扩展器



I hope this is possible and someone can help me.

Thanks in advance

What I have tried:

Creating multiple Expanders
Tried to bind a bool Array to the expander

推荐答案

我找到了一个解决方案。

我只需要将Expander模式设置为OneWay 。

那样它工作正常。

这个

I found a solution.
I only had to set the Expander mode to "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}" xmlns:x="#unknown"></expander>





我希望有一天能帮助某人



I hope this will help somebody someday


这篇关于如何仅动态扩展单击的扩展器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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