本文整理汇总了C#中System.Windows.Controls.Canvas.GetVisualChildren方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.GetVisualChildren方法的具体用法?C# Canvas.GetVisualChildren怎么用?C# Canvas.GetVisualChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Canvas
的用法示例。
在下文中一共展示了Canvas.GetVisualChildren方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddVisibileContainers
/// <summary>
/// Retrieves the visible containers in a LongListSelector and adds them to <paramref name="items"/>.
/// </summary>
/// <param name="list">LongListSelector that contains the items.</param>
/// <param name="itemsPanel">Direct parent of the items.</param>
/// <param name="items">List to populate with the containers currently in the viewport</param>
/// <param name="selectContent">
/// Specifies whether to return the container or its content.
/// For headers, we can't apply projections on the container directly
/// (or everything will go blank), so we will apply them on the
/// content instead.
/// </param>
private static void AddVisibileContainers(LongListSelector list, Canvas itemsPanel, List<KeyValuePair<double, FrameworkElement>> items, bool selectContent)
{
foreach (DependencyObject obj in itemsPanel.GetVisualChildren())
{
ContentPresenter container = obj as ContentPresenter;
if (container != null &&
(!selectContent ||
(VisualTreeHelper.GetChildrenCount(container) == 1 &&
VisualTreeHelper.GetChild(container, 0) is FrameworkElement)))
{
GeneralTransform itemTransform = null;
try
{
itemTransform = container.TransformToVisual(list);
}
catch (ArgumentException)
{
// Ignore failures when not in the visual tree
break;
}
Rect boundingBox = new Rect(itemTransform.Transform(new Point()), itemTransform.Transform(new Point(container.ActualWidth, container.ActualHeight)));
if (boundingBox.Bottom > 0 && boundingBox.Top < list.ActualHeight)
{
items.Add(
new KeyValuePair<double, FrameworkElement>(
boundingBox.Top,
selectContent
? (FrameworkElement)VisualTreeHelper.GetChild(container, 0)
: container));
}
}
}
}