//itemsControl 开始为指定的TreeView控件 item为TreeView子元素
private void PareItems(ItemsControl itemsControl, T item)
{
TreeViewItem container = itemsControl.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
if (container != null)
{
container.IsExpanded = true;
if (container.ItemContainerGenerator.Status != System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
{
container.UpdateLayout();
}
if ((container.Header as T).Children != null)
{
foreach (var it in (container.Header as T).Children)
{
PareItems(container, it);
}
}
if ((container.Header as T) ==TT) //TT要找的子元素
{
container.IsSelected = true;
container.BringIntoView();//滚动条滚动到选中的子元素
}
itemsControl = container;
}
}