c# - 如何从强名称程序集中加载 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();
}
}
解决方案
您可以启用融合日志记录并从此日志文件中获取提示。 如何在 .NET 中启用程序集绑定失败日志记录 (Fusion)
推荐阅读
- python - 无法在 Django 中发布值并创建派生值
- makefile - Makefile 中的变量扩展
- c# - ODBC ExecuteNonQuery() 挂起
- reactjs - 在反应 js 中显示 HTML 页面响应
- node.js - 尝试运行 node-express 服务器来发送电子邮件并获得无限循环
- google-sheets - 从 Google 表格获取数据到 BigQuery
- javascript - 类型“JSX.IntrinsicElements”上不存在属性。TS2339
- spring - 如何注释请求正文以描述示例
- angular - TS2322:类型“数字”不可分配给类型“字符串”
- android - 如何将矢量图像适合(或缩放)到手机/模拟器屏幕宽度(和高度,如果需要)?