完成Grid示例
This commit is contained in:
29
RazorEngineTest/ExHelper.cs
Normal file
29
RazorEngineTest/ExHelper.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Windows;
|
||||
|
||||
namespace RazorEngineTest
|
||||
{
|
||||
public static class ExHelper
|
||||
{
|
||||
public static T? FindVisualChild<T>(this DependencyObject parent, string name = "") where T : DependencyObject
|
||||
{
|
||||
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(parent, i);
|
||||
if (child is T result)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return result;
|
||||
else if (result is FrameworkElement element && element.Name == name) return result;
|
||||
}
|
||||
var descendant = child.FindVisualChild<T>(name);
|
||||
if (descendant != null) return descendant;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user