首页 > 解决方案 > 如何从强名称程序集中加载 ResourceDictionary?

问题描述

我有引用 2 个 dll 的项目。如果引用的 dll 命名不强,则资源加载正常并且我的用户控件正常工作。问题是我必须对引用的 DLL 进行强命名,现在我的用户控件给了我一个 XamlParseException System.Windows.Markup.StaticResourceHolder,其内部为“无法加载文件或程序集”。我猜 app.xaml 中的静态资源无法找到或加载,因此它认为程序集未加载。有没有解决的办法?

应用程序.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>

应用程序.xaml.cs...

 public partial class App
{
    protected override void OnStartup(StartupEventArgs e)
    {
        // referenced to MaterialDesignThemes.Wpf
        MaterialDesignThemes.Wpf.DialogHost d = new MaterialDesignThemes.Wpf.DialogHost();
        var b = d.IsOpen;

        base.OnStartup(e);
        var app = new MainWindow();
        var context = new MainWindowVM();
        app.DataContext = context;
        app.Show();
    }
}

标签: c#wpfxamlresourcedictionary

解决方案


您可以启用融合日志记录并从此日志文件中获取提示。 如何在 .NET 中启用程序集绑定失败日志记录 (Fusion)


推荐阅读