【发布时间】:2019-04-27 09:05:10
【问题描述】:
我有引用 2 个 dll 的项目。如果引用的 dll 命名不强,则资源加载正常并且我的用户控件正常工作。问题是我必须对引用的 DLL 进行强命名,现在我的用户控件给了我一个 XamlParseException System.Windows.Markup.StaticResourceHolder,其内部为“无法加载文件或程序集”。我猜 app.xaml 中的静态资源无法找到或加载,因此它认为程序集未加载。有没有办法解决这个问题?
App.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>
App.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();
}
}
【问题讨论】:
-
这应该可以正常工作。您能否说明您是如何引用 ResourceDictionary 的?
-
已编辑 OP... 项目是 .Net 4.6.1 吗?
-
能否尝试实例化应用启动代码中引用的程序集中定义的任何类型?这行得通吗?
-
已编辑的 OP 添加了 App.xaml.cs...如果这足够了,那么它可以工作。
-
也许您可以启用融合日志记录并从这些日志文件中获得提示?
标签: c# wpf xaml resourcedictionary