本文整理汇总了C#中System.Windows.Controls.TreeViewItem.UpdateLayout方法的典型用法代码示例。如果您正苦于以下问题:C# TreeViewItem.UpdateLayout方法的具体用法?C# TreeViewItem.UpdateLayout怎么用?C# TreeViewItem.UpdateLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.TreeViewItem
的用法示例。
在下文中一共展示了TreeViewItem.UpdateLayout方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectItem
private static bool SelectItem(object o, TreeViewItem parentItem)
{
if (parentItem == null)
return false;
bool isExpanded = parentItem.IsExpanded;
if (!isExpanded)
{
parentItem.IsExpanded = true;
parentItem.UpdateLayout();
}
TreeViewItem item = parentItem.ItemContainerGenerator.ContainerFromItem(o) as TreeViewItem;
if (item != null)
{
item.IsSelected = true;
return true;
}
bool wasFound = false;
for (int i = 0; i < parentItem.Items.Count; i++)
{
TreeViewItem itm = parentItem.ItemContainerGenerator.ContainerFromIndex(i) as TreeViewItem;
var found = SelectItem(o, itm);
if (!found)
itm.IsExpanded = false;
else
wasFound = true;
}
return wasFound;
}
示例2: FindItemNodeInChildren
protected TreeViewItem FindItemNodeInChildren(TreeViewItem parent, object item)
{
TreeViewItem node = null;
bool isExpanded = parent.IsExpanded;
if (!isExpanded) //Can't find child container unless the parent node is Expanded once
{
parent.IsExpanded = true;
parent.UpdateLayout();
}
foreach (object data in parent.Items)
{
node = parent.ItemContainerGenerator.ContainerFromItem(data) as TreeViewItem;
if (node != null)
{
if (data == item)
break;
node = FindItemNodeInChildren(node, item);
if (node != null)
break;
}
}
if (node == null && parent.IsExpanded != isExpanded)
parent.IsExpanded = isExpanded;
if (node != null)
parent.IsExpanded = true;
return node;
}
示例3: ExpandRecursive
/// <summary>
/// Recursively & syncronously expand all the nodes in this subtree.
/// </summary>
private static void ExpandRecursive(TreeViewItem item)
{
if (item == null)
{
return;
}
// Expand the current item
if (!item.IsExpanded)
{
item.SetCurrentValueInternal(IsExpandedProperty, BooleanBoxes.TrueBox);
}
// ApplyTemplate in order to generate the ItemsPresenter and the ItemsPanel. Note that in the
// virtualizing case even if the item is marked expanded we still need to do this step in order to
// regenerate the visuals because they may have been virtualized away.
item.ApplyTemplate();
ItemsPresenter itemsPresenter = (ItemsPresenter)item.Template.FindName("ItemsHost", item);
if (itemsPresenter != null)
{
itemsPresenter.ApplyTemplate();
}
else
{
item.UpdateLayout();
}
VirtualizingPanel virtualizingPanel = item.ItemsHost as VirtualizingPanel;
item.ItemsHost.EnsureGenerator();
for (int i = 0, count = item.Items.Count; i < count; i++)
{
TreeViewItem subitem;
if (virtualizingPanel != null)
{
// We need to bring the item into view so that the container will be generated.
virtualizingPanel.BringIndexIntoView(i);
subitem = (TreeViewItem)item.ItemContainerGenerator.ContainerFromIndex(i);
}
else
{
subitem = (TreeViewItem)item.ItemContainerGenerator.ContainerFromIndex(i);
// We dont actually need to bring this into view, but we'll do it
// anyways to maintain the same behavior as with a virtualizing panel.
subitem.BringIntoView();
}
if (subitem != null)
{
ExpandRecursive(subitem);
}
}
}
示例4: DoExpansion
/// <summary>
/// An 'Items.Refresh' call erases all the previous expansion data. This recursive
/// method complements 'CheckExpansion' method where it does the expansion of items
/// that were expanded before the refresh method closed them.
/// </summary>
/// <param name="dataVal">
/// The Observable Collection that holds all the data for the level below.
/// Each InspectionData.Derivations is also an Observable Collection.
/// </param>
/// <param name="parent">
/// If parent is null, it means there is no parent and it is the top level data.
/// Otherwise, send the parent item of the dataVal parameter
/// </param>
private void DoExpansion(ICollection<InspectionData> dataVal, TreeViewItem parent = null)
{
if (dataVal == null)
return;
foreach (InspectionData item in dataVal)
{
InspectionViewItem TLVitem;
if (parent == null)
TLVitem = (InspectionViewItem)(inspectionToolTip.ItemContainerGenerator.ContainerFromItem(item));
else
{
parent.IsExpanded = true;
parent.UpdateLayout();
TLVitem = (InspectionViewItem)(parent.ItemContainerGenerator.ContainerFromItem(item));
}
if (item.IsExpanded)
{
if (null != TLVitem)
{
TLVitem.IsExpanded = true;
}
}
if (item.HasItems && item.IsExpanded)
{
DoExpansion(item.Derivations, TLVitem);
}
}
}