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


C# FrameworkElement.GetVisualAncestors方法代码示例

本文整理汇总了C#中System.Windows.FrameworkElement.GetVisualAncestors方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.GetVisualAncestors方法的具体用法?C# FrameworkElement.GetVisualAncestors怎么用?C# FrameworkElement.GetVisualAncestors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.FrameworkElement的用法示例。


在下文中一共展示了FrameworkElement.GetVisualAncestors方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetItemUnderMouse

    /// <summary>
    /// Get the item under the mouse
    /// </summary>
    /// <param name="senderElement">The clicked or hovered element</param>
    /// <param name="e"></param>
    /// <param name="returnSelectableItemIfAny">Return the clicked or hovered item inside the trigger element if the latter is a DataGrid, a ListBox or a TreeView</param>
    /// <param name="selectItemIfSelectable">Select the item if lies in a ListBox, Datagrid or TreeView</param>
    /// <returns>The item under the mouse</returns>
    private FrameworkElement GetItemUnderMouse(FrameworkElement senderElement, MouseEventArgs e, bool returnSelectableItemIfAny, bool selectItemIfSelectable) {
      VisualTreeElementsUnderMouse = VisualTreeHelper.FindElementsInHostCoordinates(
        e.GetPosition(Application.Current.RootVisual),
        senderElement.GetVisualAncestors().Last() as FrameworkElement);

      return PopupMenuUtils.GetItemUnderMouse(VisualTreeElementsUnderMouse, senderElement, returnSelectableItemIfAny, selectItemIfSelectable);
    }
开发者ID:tormoz70,项目名称:Bio.Framework.8,代码行数:15,代码来源:PopupMenu.cs

示例2: IsOnScreen

        /// <summary>
        /// Indicates whether the specified framework element
        /// is within the bounds of the application's root visual.
        /// </summary>
        /// <param name="element">The framework element.</param>
        /// <returns>
        /// True if the rectangular bounds of the framework element
        /// are completely outside the bounds of the application's root visual.
        /// </returns>
        private static bool IsOnScreen(FrameworkElement element)
        {
            PhoneApplicationFrame root = Application.Current.RootVisual as PhoneApplicationFrame;

            if (root == null)
            {
                return false;
            }

            GeneralTransform generalTransform;
            double height = root.ActualHeight;
            double width = root.ActualWidth;

            try
            {
                generalTransform = element.TransformToVisual(root);
            }
            catch (ArgumentException)
            {
                return false;
            }

            Rect bounds = new Rect(
                generalTransform.Transform(Origin),
                generalTransform.Transform(new Point(element.ActualWidth, element.ActualHeight)));

            bool isParentTransparent = false;
            IList<FrameworkElement> ancestors = element.GetVisualAncestors().ToList();

            if (ancestors != null)
            {
                for (int i = 0; i < ancestors.Count; i++)
                {
                    if (ancestors[i].Opacity <= 0.001)
                    {
                        isParentTransparent = true;
                        break;
                    }
                }
            }

            return (bounds.Bottom > 0) && (bounds.Top < height) 
                && (bounds.Right > 0) && (bounds.Left < width) 
                && !isParentTransparent;
        }
开发者ID:5nophilwu,项目名称:S1Nyan,代码行数:54,代码来源:TurnstileFeatherEffect.cs

示例3: GetMergedStyleDictionary

        /// <summary>
        /// Retrieves or creates the merged style dictionary of an element.
        /// </summary>
        /// <param name="styledElement">A styled element.</param>
        /// <returns>The merged dictionary of the element.</returns>
        private static BaseMergedStyleDictionary GetMergedStyleDictionary(FrameworkElement styledElement)
        {
            Debug.Assert(styledElement != null, "styledElement cannot be null.");

            IList<FrameworkElement> ancestorsInclusive = styledElement.GetVisualAncestors().Append(styledElement).Reverse().ToList();

            IEnumerable<FrameworkElement> ancestorsTopToBottom = ancestorsInclusive;

            BaseMergedStyleDictionary initialDictionary = null;
            if (UseApplicationResources)
            {
                initialDictionary = new MergedStyleResourceDictionary(ApplicationExternalResourceDictionary ?? Application.Current.Resources);
            }
            else
            {
                FrameworkElement topLevelElement = ancestorsInclusive[0];
                initialDictionary = new MergedStyleResourceDictionary(ImplicitStyleManager.GetExternalResourceDictionary(topLevelElement) ?? topLevelElement.Resources);

                ancestorsTopToBottom = ancestorsInclusive.Skip(1);
            }

            BaseMergedStyleDictionary styleDictionary =
                ancestorsTopToBottom.Aggregate(
                    initialDictionary,
                    (dictionary, ancestor) => new MergedStyleResourceDictionary(ImplicitStyleManager.GetExternalResourceDictionary(ancestor) ?? ancestor.Resources) { Parent = dictionary });

            return styleDictionary;
        }
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:33,代码来源:ImplicitStyleManager.cs


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