继承的窗口不能有名字?

sab*_*ber 8 c# wpf inheritance xaml

我在命名从其基本窗口继承的Window时遇到了麻烦,当我尝试给我的窗口命名时,我得到了以下错误.

BaseWindow类型不能具有Name属性.没有默认构造函数的值类型和类型可以用作ResourceDictionary中的项.

XAML:

<log:BaseWindow 
   x:Class="EtraabMessenger.MainWindow"
   x:Name="main"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
   xmlns:log="clr-namespace:EtraabMessenger.MVVM.View.Controls" 
   xmlns:VMCore="clr-namespace:EtraabMessenger.MVVM.VMCore" 
   VMCore:WindowClosingBehavior.Closing="{Binding DoCloseMainWindowCommand}"
   Height="464" Width="279">

</log:BaseWindow>
Run Code Online (Sandbox Code Playgroud)

编辑:这是我的BaseWindow类

public abstract class BaseWindow : Window, INotifyPropertyChanged
{
    protected BaseWindow()
    {
        // Note (Important) : This message should register on all windows
        // TODO : I'm planning to move this registeration to BaseWindow class
        Messenger.Register<bool>(GeneralToken.ClientDisconnected, DisconnectFromServer);
    }

    protected abstract void DisconnectFromServer(bool isDisconnected);
    protected abstract void RegisterTokens();
    protected abstract void UnRegisterTokens();

    ....
    ....
    ....

}
Run Code Online (Sandbox Code Playgroud)

任何建议都会有所帮助.

H.B*_*.B. 18

显然,你的基本窗口,如错误所述,需要一个公共默认的构造函数(一个没有参数),它也可能不是抽象的,因为需要创建它的一个实例.

  • @SaberAmani:当你尝试在XAML中创建一个实例时它确实会引起问题,这只适用于公共构造函数,也不能是抽象的,我只测试了它. (2认同)