我有一个MainMenu
在我的MainWindow
视图中使用的用户控件,它有一个MainWindowViewModel
. MainMenu
标记开始像:
<UserControl x:Class="ApptEase.Client.Shell.Controls.MainMenu"
....
d:DesignHeight="25">
<UserControl.DataContext>
<shell:MainWindowViewModel />
</UserControl.DataContext>
<Menu Height="25" VerticalAlignment="Top">
<MenuItem Header="_File">
在设计模式下,我的错误列表中有 2 个错误,它们都是:
无法将“System.Windows.Application”类型的对象转换为“ApptEase.Client.App”类型
第一个出现在<shell:MainWindowViewModel />
上面用户控件标记的行中。第二个出现在下面<shell:MainMenu Grid.Row="0" />
的MainWindow
标记摘录行中。
主窗口摘录:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<shell:MainMenu Grid.Row="0" />
<ContentControl Grid.Row="1" prism:RegionManager.RegionName="ContentRegion" />
</Grid>
我MainWindowViewModel
来自BaseViewModel
:
public abstract class BaseViewModel : BindableBase
{
protected BaseViewModel()
{
AppState = ((App)Application.Current).AppState;
}
...
}
如果我注释掉该((App)Application.Current).AppState
行,错误就会消失。然而,当我构建时,除了“成功构建”之外,我在输出窗口中看不到任何输出,并且应用程序启动良好,即BaseViewModel
ctor 执行良好,无一例外。
如果我别无选择,只能接受错误消息是无害的,有没有办法抑制它们?我没有看到编译器指令在 XAML 标记中起作用。