本文整理汇总了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);
}
示例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;
}
示例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;
}