diff --git a/DeedyDesigner/Deedy.Activity/Helper.cs b/DeedyDesigner/Deedy.Activity/Helper.cs
index 26239ea..7df9009 100644
--- a/DeedyDesigner/Deedy.Activity/Helper.cs
+++ b/DeedyDesigner/Deedy.Activity/Helper.cs
@@ -60,7 +60,7 @@ namespace Deedy.Activity
/// 要查找的祖先元素类型
/// 起始子元素
/// 要查找的祖先层级(1=父级,2=祖父级等)
- /// 找到的祖先元素,若未找到则返回null
+ /// 找到的祖先元素,若未找到则返回「null」
public static T? FindAncestor(this DependencyObject @object, int level = 1) where T : DependencyObject
{
if (@object == null || level < 1) return null;
@@ -82,5 +82,27 @@ namespace Deedy.Activity
return null;
}
+ ///
+ /// 在可视化树中查找指定类型的子级元素,支持元素名称
+ ///
+ /// 要查找的子级元素类型
+ /// 起始父元素
+ /// 要查找的子级元素名称,只对「FrameworkElement」类型元素生效
+ /// 找到的子级元素,若未找到则返回「null」
+ public static T? FindVisualChild(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(name);
+ if (descendant != null) return descendant;
+ }
+ return null;
+ }
}
}
diff --git a/DeedyDesigner/Deedy.Wpf/WindowHeader.cs b/DeedyDesigner/Deedy.Wpf/WindowHeader.cs
index c07b9f0..c4cbcb5 100644
--- a/DeedyDesigner/Deedy.Wpf/WindowHeader.cs
+++ b/DeedyDesigner/Deedy.Wpf/WindowHeader.cs
@@ -4,7 +4,7 @@ using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows.Media;
-using System.Windows.Shell;
+using Shell = System.Windows.Shell;
namespace Deedy
{
@@ -84,7 +84,7 @@ namespace Deedy
private Menu? MainMenu;
private Window? Target;
- private WindowChrome? Chrome;
+ private Shell.WindowChrome? Chrome;
private static bool IsNeedOverrideMetadata = true;
public WindowHeader() { }
@@ -140,10 +140,10 @@ namespace Deedy
if (this.Background == BackgroundProperty.DefaultMetadata.DefaultValue) this.SetBinding(BackgroundProperty, new Binding() { Source = this.Target, Path = new PropertyPath(BackgroundProperty.Name) });
if (this.BorderBrush == BorderBrushProperty.DefaultMetadata.DefaultValue) this.SetBinding(BorderBrushProperty, new Binding() { Source = this.Target, Path = new PropertyPath(BorderBrushProperty.Name) });
//这是第【3】步
- this.Chrome = new WindowChrome() { CaptionHeight = this.ActualHeight };
- WindowChrome.SetWindowChrome(this.Target, this.Chrome);
- WindowChrome.SetIsHitTestVisibleInChrome(this.Container, true);
- WindowChrome.SetIsHitTestVisibleInChrome(this.Controller, true);
+ this.Chrome = new Shell.WindowChrome() { CaptionHeight = this.ActualHeight };
+ Shell.WindowChrome.SetWindowChrome(this.Target, this.Chrome);
+ Shell.WindowChrome.SetIsHitTestVisibleInChrome(this.Container, true);
+ Shell.WindowChrome.SetIsHitTestVisibleInChrome(this.Controller, true);
if (this.Controller != null)
{