本文整理汇总了C#中System.Windows.DependencyObject.GetVisualAncestors方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.GetVisualAncestors方法的具体用法?C# DependencyObject.GetVisualAncestors怎么用?C# DependencyObject.GetVisualAncestors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.GetVisualAncestors方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsAncestorOf
/// <summary>
/// Determines whether the visual object is an ancestor of the descendant visual object.
/// </summary>
/// <param name="element">The <see cref="UIElement"/>.</param>
/// <param name="descendant">The <see cref="DependencyObject"/>.</param>
/// <returns>
/// <see langword="true"/> if the <paramref name="element"/> is an ancestor of
/// <paramref name="descendant"/>; otherwise, <see langword="false"/>.
/// </returns>
public static bool IsAncestorOf(this UIElement element, DependencyObject descendant)
{
if (element == null || descendant == null)
return false;
if (element == descendant)
return true;
return descendant.GetVisualAncestors().Contains(element);
}
示例2: OnVisibleChanged
private static void OnVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue != e.OldValue) {
var appbar = ((BindableAppBar)d).ApplicationBar;
appbar.IsVisible = (bool)e.NewValue;
var page = d.GetVisualAncestors().OfType<PhoneApplicationPage>().FirstOrDefault();
// Swapping bars?
if (page != null && appbar.IsVisible && page.ApplicationBar != appbar) {
page.ApplicationBar = appbar;
Log.Info("Set appbar as foreground appbar");
}
}
}
示例3: OnYAxisChanged
private static void OnYAxisChanged(DependencyObject element, DependencyPropertyChangedEventArgs eventArgs)
{
if (eventArgs.OldValue == eventArgs.NewValue)
return;
var chartPanel = element.GetVisualAncestors()
.OfType<ChartPanel>()
.FirstOrDefault();
if (element is IChartElement)
{
var chartElement = (IChartElement)element;
var yAxis = (Axis)eventArgs.NewValue;
// Synchronize the attached dependency property ChartPanel.XAxis with
// the dependency property ChartElement.XAxis.
chartElement.YAxis = yAxis;
}
else if (element is UIElement)
{
// Size of the element might have changed.
// --> Re-measure element.
var uiElement = (UIElement)element;
uiElement.InvalidateMeasure();
// Reposition element in ChartPanel.
if (chartPanel != null)
chartPanel.InvalidateArrange();
}
if (chartPanel != null)
chartPanel.DetectAxes();
}
示例4: OnViewportWidthChanged
private static void OnViewportWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
d.GetVisualAncestors().OfType<DataGrid>().Last().OnViewportWidthChanged(e);
}
示例5: OnPositioningChanged
//--------------------------------------------------------------
#region Methods
//--------------------------------------------------------------
private static void OnPositioningChanged(DependencyObject element, DependencyPropertyChangedEventArgs eventArgs)
{
var chartPanel = element.GetVisualAncestors().OfType<ChartPanel>().FirstOrDefault();
if (chartPanel != null)
chartPanel.InvalidateArrange();
}