如何在 Xaml 中完成 "Windows" 类型的 DependencyProperty

How do I complete a DependencyProperty of type "Windows" in Xaml

如何在 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”中输入什么属性来表示这个window?

customBox.WindowHandle = this;//in C#
<UControl:CustomBox x:Name="customBox" WindowHandle="?"/><!--in xaml-->

要绑定到 window,您可以像这样使用 FindAncestor

<UControl:CustomBox ...
  WindowHandle="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" />