我在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中定義基礎控件。 –
你想從主窗口繼承什麼?您可以使用基礎樣式來完成此操作。 –