本文整理汇总了C#中DependencyObject.LookupEntry方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.LookupEntry方法的具体用法?C# DependencyObject.LookupEntry怎么用?C# DependencyObject.LookupEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.LookupEntry方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnlinkContainerFromItem
internal static void UnlinkContainerFromItem(DependencyObject container, object item, IGeneratorHost host)
{
// When a container is removed from the tree, its future takes one of
// two forms:
// a) [normal mode] the container becomes eligible for GC
// b) [recycling mode] the container joins the recycled list, and
// possibly re-enters the tree at some point, usually with a
// different item.
//
// As Dev10 bug 452669 and some "subtle issues" that arose in the
// container recycling work illustrate, it's important that the container
// and its subtree sever their connection to the data item. Otherwise
// you can get aliasing - a dead container reacting to the same item as a live
// container. Even without aliasing, it's a perf waste for a dead container
// to continue reacting to its former data item.
//
// On the other hand, it's a perf waste to spend too much effort cleaning
// up the container and its subtree, since they will often just get GC'd
// in the near future.
//
// WPF initially did a full cleanup of the container, removing all properties
// that were set in PrepareContainerForItem. This avoided aliasing, but
// was deemed too expensive, especially for scrolling. For Windows OS Bug
// 1445288, all this cleanup work was removed. This sped up scrolling, but
// introduced the problems cited in Dev10 452669 and the recycling "subtle
// issues". A compromise is needed.
//
// The compromise is tell the container to attach to a sentinel item
// BindingExpressionBase.DisconnectedItem. We allow this to propagate into the
// conainer's subtree through properties like DataContext and
// ContentControl.Content that are normally set by PrepareItemForContainer.
// A Binding that sees the sentinel as the data item will disconnect its
// event listeners from the former data item, but will not change its
// own value or invalidate its target property. This avoids the cost
// of re-measuring most of the subtree.
container.ClearValue(ItemForItemContainerProperty);
// TreeView virtualization requires that we call ClearContainer before setting
// the DataContext to "Disconnected". This gives the TreeViewItems a chance
// to save "Item values" in the look-aside table, before that table is
// discarded. (See Dev10 628778)
host.ClearContainerForItem(container, item);
if (container != item)
{
DependencyProperty dp = FrameworkElement.DataContextProperty;
#if DEBUG
// Some ancient code at this point handled the case when DataContext
// was set via an Expression (presumably a binding). I don't think
// this actually happens any more. Just in case...
EntryIndex entryIndex = container.LookupEntry(dp.GlobalIndex);
Debug.Assert(!container.HasExpression(entryIndex, dp), "DataContext set by expression (unexpectedly)");
#endif
container.SetValue(dp, BindingExpressionBase.DisconnectedItem);
}
}
示例2: LinkContainerToItem
// establish the link from the container to the corresponding item
internal static void LinkContainerToItem(DependencyObject container, object item)
{
// always set the ItemForItemContainer property
container.ClearValue(ItemForItemContainerProperty);
container.SetValue(ItemForItemContainerProperty, item);
// for non-direct items, set the DataContext property
if (container != item)
{
#if DEBUG
// Some ancient code at this point handled the case when DataContext
// was set via an Expression (presumably a binding). I don't think
// this actually happens any more. Just in case...
DependencyProperty dp = FrameworkElement.DataContextProperty;
EntryIndex entryIndex = container.LookupEntry(dp.GlobalIndex);
Debug.Assert(!container.HasExpression(entryIndex, dp), "DataContext set by expression (unexpectedly)");
#endif
container.SetValue(FrameworkElement.DataContextProperty, item);
}
}