13

I'm having trouble with naming my Window which is inherited from its Base Window, when I try to give a name to my Window I get following error.

The type BaseWindow cannot have a Name attribute. Values types and types without a default constructor can be used as items within 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>

EDIT : Here is my BaseWindow class

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();

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

}

Any advice will be helpful.

Saber Amani
  • 6,409
  • 12
  • 53
  • 88

1 Answers1

26

Your base window apparently, as the error states, needs a public default contructor (one without arguments), it also may not be abstract because an instance of it needs to be created.

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • There is something else, my BaseWindow is a abstract class with protected constructor without any params. – Saber Amani Jul 10 '12 at 18:43
  • @SaberAmani: That doesn't sound good, most things XAML require public members. – H.B. Jul 10 '12 at 18:44
  • But It's inheritance and I don't think it causes problem, Right ? – Saber Amani Jul 10 '12 at 18:45
  • 2
    @SaberAmani: It does cause problems as you try to create an instance in XAML, this only works with a public constructor, also it cannot be abstract either, i just tested this. – H.B. Jul 10 '12 at 18:49