【发布时间】:2021-10-11 08:04:36
【问题描述】:
如何在 Xaml 中完成“Windows”类型的 DependencyProperty?
我有:
public Window WindowHandle
{
get { return (Window)GetValue(WindowHandleProperty); }
set { SetValue(WindowHandleProperty, value); }
}
public static readonly DependencyProperty WindowHandleProperty =
DependencyProperty.Register("WindowHandle", typeof(Window), typeof(CustomBox), new PropertyMetadata(null));
应该在“WindowHandle”属性中输入什么来指示这个窗口?
customBox.WindowHandle = this;//in C#
<UControl:CustomBox x:Name="customBox" WindowHandle="?"/><!--in xaml-->
【问题讨论】:
-
WindowHandle="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"? -
它有效,非常感谢。
标签: c# xaml custom-controls dependency-properties