根據這篇文章提供的方法會致使搜索變慢及有時候搜索不到 WPF中ItemsControl應用虛擬化時找到子元素的方法,spa
具體能夠修改成下面代碼:.net
//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-》CallBringIndexIntoViewcode