我在WPF中有一个成本窗口,我想用它作为其他窗口的基本窗口。
当我尝试继承它,我写在XAML:继承自WPF中的自定义窗口
<my:MyWindow x:Class="NewWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:my="clr-namespace:MyNamesapce;assembly=MyAssembly"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
在的.cs代码中,我写道:
namespace SomeOtherNamespace
{
public partial class NewWindow: MyWindow
{
internal NewWindow(Control ctrl) : base(ctrl)
{
InitializeComponent();
this.ResizeMode = System.Windows.ResizeMode.NoResize;
}
}
}
但后来我得到的错误:
cannot be the root of a XAML file because it was defined using XAML.
我在做什么错,我该如何解决?
.cs类中的内容是什么? – ZSH
如果要在XAML中派生控件,则无法在XAML中定义基础控件。 –
你想从主窗口继承什么?您可以使用基础样式来完成此操作。 –