界面初始化更新异常,更新工作要放在Loaded事件中,且注意使用UpdateLayout();

要放在Loaded事件中

private void Expand()
{
List list = new List();
TreeNodeModel node = vm.selNode;
while (node != null)
{
if (node.Parent != null)
list.Insert(0, node.Parent.Children.IndexOf(node));
else
list.Insert(0, 0);
node = node.Parent;
}
ItemsControl item = tvIns;
foreach (int i in list)
{
item = item.ItemContainerGenerator.ContainerFromIndex(i) as ItemsControl;
if (item == null) break;
(item as TreeViewItem).IsExpanded = true;
item.UpdateLayout();
}
if (item != null)
(item as TreeViewItem).BringIntoView();
}

转载于:https://www.cnblogs.com/glyson/p/9245514.html

你可能感兴趣的:(界面初始化更新异常,更新工作要放在Loaded事件中,且注意使用UpdateLayout();)