当前位置: 首页>>代码示例>>C#>>正文


C# Canvas.GetVisualChildren方法代码示例

本文整理汇总了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));
                    }
                }
            }
        }
开发者ID:JanJoris,项目名称:VikingApp,代码行数:47,代码来源:LongListSelectorExtensions.cs


注:本文中的System.Windows.Controls.Canvas.GetVisualChildren方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。