【发布时间】:2012-07-10 18:31:04
【问题描述】:
我在命名从其基本窗口继承的窗口时遇到问题, 当我尝试为我的窗口命名时,出现以下错误。
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>
编辑:这是我的 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();
....
....
....
}
任何建议都会有所帮助。
【问题讨论】:
-
Values types and types without a default constructor can be used as items within ResourceDictionary.- 真的是“不能”吗? -
解决方案是否像在
BaseWindow类中添加默认(空)构造函数一样简单? -
@RobertHarvey:实际上消息中没有“不”,如果其他引用错误的情况可以通过......
-
@H.B.我怀疑这是一个错字,因为我希望在原始措辞中看到“仅”这个词。
-
@RobertHarvey:是的,“唯一”会有所帮助...
标签: c# wpf xaml inheritance