Expander是从动态资源中展开的,如果手动更改则不再起作用

发布于 2025-01-05 09:48:00 字数 1256 浏览 1 评论 0原文

经过大量搜索后,我想出了这段代码来通过代码扩展我的扩展器: 我是 XAML/WPF 的新手,所以我很可能可以以更好的方式做到这一点,但经过大量搜索后,我很高兴我让它工作(但尚未完全)

XAML: 将其添加到“标题”

 xmlns:System="clr-namespace:System;assembly=mscorlib"

,然后将其添加到 Window.Recources

 <System:Boolean x:Key="booexapnders">False          
        </System:Boolean>

这是扩展器的一部分(扩展器是在列表视图中的数据模板中制作的)

  <ListView x:Name="lsvteamleft" SelectionChanged="lsvleft_SelectionChanged"  GotFocus="lsv_GotFocus" ScrollViewer.VerticalScrollBarVisibility="Visible">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <Expander Header="{Binding}" Margin="0,0,0,2" IsExpanded="{DynamicResource booexapnders}" >
                                    <Expander.HeaderTemplate>

我可以向此列表视图添加多个项目,因此有多个膨胀器制成。 在 c# 中,我使用代码:

this.Resources["booexapnders"] = true; // to expand all the expanders
this.Resources["booexapnders"] = false; // to colapse all the expanders

现在的问题是,例如。我在列表视图中有 5 个项目,我想查看 1 的扩展版本,我用一个按钮将它们全部折叠(这有效),并在列表视图中手动展开我想要的项目(展开以查看更多信息),但是在我之后这样做后,我刚刚手动展开的那个将不再对“全部展开”或“全部折叠”按钮做出反应。

先感谢您。

After lots of searching I came up with this code to expand my expander by code:
I am new to XAML/WPF so it is very well possible I can do this in better ways, but after lots of searching I am happy I got it working(but not yet completly)

XAML:
Added this to the "header"

 xmlns:System="clr-namespace:System;assembly=mscorlib"

then added this to Window.Recources

 <System:Boolean x:Key="booexapnders">False          
        </System:Boolean>

Here is the part of the expander(the expander is made in a datatemplate that is in a Listview)

  <ListView x:Name="lsvteamleft" SelectionChanged="lsvleft_SelectionChanged"  GotFocus="lsv_GotFocus" ScrollViewer.VerticalScrollBarVisibility="Visible">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <Expander Header="{Binding}" Margin="0,0,0,2" IsExpanded="{DynamicResource booexapnders}" >
                                    <Expander.HeaderTemplate>

I am able to add multiple items to this listview and so there are multiple expanders made.
In c# I use the code:

this.Resources["booexapnders"] = true; // to expand all the expanders
this.Resources["booexapnders"] = false; // to colapse all the expanders

Now the problem is, for example. I got 5 items in the listview and I want to see the expanded version of 1, I colapse them all with a button(this works) and manualy expand the one I want(expanded to see more info) in the listview, HOWEVER after I did this the one that I just manualy expanded won t react anymore on the "expand all" or "collapse all" buttons.

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残月升风 2025-01-12 09:48:00

您应该将 IsExpanded 绑定到项目上的属性,然后展开或折叠您在集合上迭代的所有内容并更改所有项目的值,要更改您只需为该单个项目执行此操作,很多更多控制。

You should bind IsExpanded to a property on your item, then to expand or collapse all you iterate over the collection and change the value on all items, to change one you just do it for that single item, much more control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文