首页 > Windows开发 > 详细

wpf 虚拟化操作异常

时间:2017-01-10 11:29:21      阅读:279      评论:0      收藏:0      [点我收藏+]

根据这篇文章提供的方法会导致搜索变慢及有时候搜索不到 WPF中ItemsControl应用虚拟化时找到子元素的方法

具体可以修改为下面代码:

 //Action action = () =>
                //{
                try
                {
                    TreeViewItem itemSelected = null;

                    //Force to generate every treeView item by using scroll item
                    if (virtualizingPanel != null)
                    {
                        try
                        {
                            if (isCallEnd)
                            {
                                isCallEnd = false;
                                virtualizingPanel.CallBringIndexIntoView(selectedIndex);
                                isCallEnd = true;
                            }
                        }
                        catch (System.Exception ex)
                        {
                            Logger.Error("CallBringIndexIntoView exception : ", ex);
                        }

                        itemSelected = (TreeViewItem)_currentSelectedItem.ItemContainerGenerator.ContainerFromIndex(selectedIndex);
                    }


增加变量isCallEnd 用来防止循环调用,-》CallBringIndexIntoView-》ItemContainerGenerator_StatusChanged-》treeViewItem_BringIntoView-》CallBringIndexIntoView

 

wpf 虚拟化操作异常

原文:http://www.cnblogs.com/yangleiWPF/p/6268534.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!