企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
        privateTreeViewItemFindTreeViewItem(ItemsControlcontainer,objectitem)        {           if(null==container||null==item)            {               returnnull;            }           if(container.DataContext==item)            {               returncontainerasTreeViewItem;            }           intcount=container.Items.Count;           for(inti= 0;i<count;i++)            {               TreeViewItemsubContainer= (TreeViewItem)container.ItemContainerGenerator.ContainerFromIndex(i);               if(null==subContainer)                {                   continue;                }               // Search the next level for the object.               TreeViewItemresultContainer=FindTreeViewItem(subContainer,item);               if(null!=resultContainer)                {                   returnresultContainer;                }            }           returnnull;        } [/////使用上述方法遍历]() , 然后设置IsSelected属性  privatestaticvoidSelectedItemChanged(DependencyObjectd,DependencyPropertyChangedEventArgse)        {           //           SelectedProtocolControlspc=dasSelectedProtocolControl;           if(null!=spc)            {               if(e.NewValue!=spc.trvSelectedProtocol.SelectedItem)                {                   //TreeViewItem tviNew = spc.trvSelectedProtocol.ItemContainerGenerator.ContainerFromItem(e.NewValue) as TreeViewItem;                   TreeViewItemtviNew=spc.FindTreeViewItem(spc.trvSelectedProtocol,e.NewValue);                   if(null!=tviNew)                    {                       tviNew.IsSelected=true;                    }                }               if(null!=e.OldValue)                {                   //TreeViewItem tviOld = spc.trvSelectedProtocol.ItemContainerGenerator.ContainerFromItem(e.OldValue) as TreeViewItem;                   TreeViewItemtviOld=spc.FindTreeViewItem(spc.trvSelectedProtocol,e.OldValue);                   if(null!=tviOld)                    {                       tviOld.IsSelected=false;                    }                }            }           System.Diagnostics.Debug.WriteLine("SelectedItemChanged...");        }