准备继续优化
This commit is contained in:
@@ -60,7 +60,7 @@ namespace Deedy.Activity
|
||||
/// <typeparam name="T">要查找的祖先元素类型</typeparam>
|
||||
/// <param name="object">起始子元素</param>
|
||||
/// <param name="level">要查找的祖先层级(1=父级,2=祖父级等)</param>
|
||||
/// <returns>找到的祖先元素,若未找到则返回null</returns>
|
||||
/// <returns>找到的祖先元素,若未找到则返回「null」</returns>
|
||||
public static T? FindAncestor<T>(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;
|
||||
}
|
||||
/// <summary>
|
||||
/// 在可视化树中查找指定类型的子级元素,支持元素名称
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要查找的子级元素类型</typeparam>
|
||||
/// <param name="parent">起始父元素</param>
|
||||
/// <param name="name">要查找的子级元素名称,只对「FrameworkElement」类型元素生效</param>
|
||||
/// <returns>找到的子级元素,若未找到则返回「null」</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user