我设法让这个工作如下:
家长控制:
public class PopupWindow : UserControl
{
}
继承控制:
后面的代码:
public partial class PopupWindowChild
{
public PopupWindowChild()
{
InitializeComponent();
}
}
XAML:
<Controls:PopupWindow x:Class="MyNamespace.Controls.PopupWindowChild"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MyNamespace.Controls">
<TextBlock Text="Blah" />
</Controls:PopupWindow>
主视图:
<Window x:Class="MyNamespace.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MyNamespace.Controls">
<Controls:PopupWindow />
</Window>
在生成代码之前,您的 XAML 不会识别您的控件。一旦构建并运行,我会在我的主视图中看到“Blah”,正如预期的那样。