我无法从app.xaml中加载ResourceDictionary.MergedDictionaries。
我的WPF应用程序有一个静态类,其中设置了Main定义和启动对象。在Main中,我创建了一个App实例并运行它。重写OnStartup将触发,并且mainwindow.cs InitializeComponent给出错误“消息”,无法找到名为“ MaterialDesignFloatingActionMiniAccentButton”的资源。如果将资源放在mainwindow.xaml中,则一切都很好,但是我希望它们在应用程序级别加载,因此它们不在每个页面中。任何帮助表示赞赏。
public partial class App
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var app = new MainWindow();
var context = new MainWindowViewModel();
app.DataContext = context;
app.Show();
}
}
从主要..
var app = new App();
app.Run();
app.xaml ..
<Application x:Class="GS.Server.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Grey.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Red.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>