我正在尝试使用 MVVMLight 工具包和Modern UI WPF来使用 c# 创建一个新的 WPF 应用程序。
我创建了一个新的基于 MVVMLight 的项目。我使用 Nuget 安装了 Modern UI WPF。
我将以下 xaml 添加到文件中的Application.resources
部分App.xaml
。注意:我添加了x:Key="ModernUI"
这不是来自文档的。但必须添加它以供应用程序编译。这是我的 App.xaml 代码的样子
<Application x:Class="Project.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:Project.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ignore="http://www.galasoft.ch/ignore"
StartupUri="MainWindow.xaml"
mc:Ignorable="d ignore">
<Application.Resources>
<!--Global View Model Locator-->
<vm:ViewModelLocator x:Key="Locator"
d:IsDataSource="True" />
<ResourceDictionary x:Key="ModernUI">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
<ResourceDictionary x:Key="ModernUI">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
然后我改变了我的MainWindow.xaml.cs to inherit
ModernWindow instead of
Window and added the following after the
InitilizeComponent()`
Style = (Style)App.Current.Resources["BlankWindow"];
然后我将我的代码稍微更改XAML
为以下
<mui:ModernWindow x:Class="InventoryManagement.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ignore="http://www.galasoft.ch/ignore"
mc:Ignorable="d ignore"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
WindowState="Maximized"
Title="Inventory Management"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Skins/MainSkin.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<TextBlock FontSize="36"
FontWeight="Bold"
Foreground="Purple"
Text="{Binding WelcomeTitle}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
TextWrapping="Wrap" />
</Grid>
</mui:ModernWindow >
应用程序编译,但我得到一个没有内容的黑屏。我该如何解决这个问题?