在WPF中保留扩展器状态 [英] Retain expander state in WPF

查看:72
本文介绍了在WPF中保留扩展器状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个listview,在扩展器下进行分组。这些项目是动态生成的。我可以访问窗口控件中的所有扩展器并保存它们的状态。之后,listview的item source属性被更改。现在,如果我尝试获取扩展器或任何其他UI控件,该函数始终返回null。功能如下:







I have listview with grouping under an expander. The items are dynamically generated. I can Access all the expanders in window control and save their state. Afterwards the item source property of listview is changed. Now if I try to get expanders or any other UI control, the function always returns null. The function is given below



public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject<br />
        {<br />
            if (depObj != null)<br />
            {<br />
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)<br />
                {<br />
                    DependencyObject child = VisualTreeHelper.GetChild(depObj, i);<br />
                    if (child != null && child is T)<br />
                    {<br />
                        yield return (T)child;<br />
                    }<br />
<br />
                    foreach (T childOfChild in FindVisualChildren<T>(child))<br />
                    {<br />
                        yield return childOfChild;<br />
                    }<br />
                }<br />
            }<br />
        }





我尝试过:



我尝试过使用其他几个功能但无济于事。



What I have tried:

I have tried using several other functions but to no avail.

推荐答案

I我快速浏览了 Google [ ^ ]并找到了这个解决方案: wpf - 如何在列表视图的组头中保存IsExpanded状态 - Take 2 - Stack溢出 [ ^ ]
I had a quick look on Google[^] and found this solution: wpf - How to save the IsExpanded state in group headers of a listview - Take 2 - Stack Overflow[^]


这篇关于在WPF中保留扩展器状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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