本文整理汇总了C#中System.Windows.DependencyObject.GetVisualSubtree方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.GetVisualSubtree方法的具体用法?C# DependencyObject.GetVisualSubtree怎么用?C# DependencyObject.GetVisualSubtree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.GetVisualSubtree方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnChartPanelChanged
private void OnChartPanelChanged(DependencyObject source)
{
if (_chartElements != null)
{
((INotifyCollectionChanged)_chartElements).CollectionChanged -= OnChartElementsChanged;
_chartElements = null;
}
if (source != null)
{
var chartPanel = source.GetVisualSubtree().OfType<ChartPanel>().FirstOrDefault();
if (chartPanel != null)
{
_chartElements = chartPanel.ChartElements;
((INotifyCollectionChanged)_chartElements).CollectionChanged += OnChartElementsChanged;
}
}
Update();
}
示例2: OnPieChartChanged
private void OnPieChartChanged(DependencyObject source)
{
// Unsubscribe from previous collection.
if (_pieChartSubscription != null)
{
_pieChartSubscription.Dispose();
_pieChartSubscription = null;
}
// Get pie chart from source.
if (source != null)
_pieChart = source.GetVisualSubtree().OfType<PieChart>().FirstOrDefault();
if (_pieChart != null)
{
// Bind legend title to pie chart title.
SetBinding(TitleProperty, new Binding("Title") { Source = _pieChart });
// Subscribe to changes in pie chart using weak event pattern.
_pieChartSubscription =
WeakEventHandler<EventArgs>.Register(
_pieChart,
this,
(sender, handler) => sender.Updated += handler,
(sender, handler) => sender.Updated -= handler,
(listener, sender, eventArgs) => listener.Update());
}
else
{
// Reset legend title.
ClearValue(TitleProperty);
}
Update();
}