我有一个名为MyApp的WPF应用程序,它带有一个单独的程序集MyApp.Infrastructure。在MyApp.Infrastructure中,我有一个ResourceDictionary
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<BitmapImage x:Key="leftImage" UriSource="/Images/left.png" />
<BitmapImage x:Key="errorImage" UriSource="/Images/error.png" />
</ResourceDictionary>
图像也位于MyApp.Infrastructure中。
在MyApp中,我有以下app.xaml:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyApp.Infrastructure;component/ImageDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
现在,我在MyApp.Infrastructure中有一个用户控件,我想在该控件中加载资源。当我这样做时,它可以在设计器中工作,但不能在运行时中工作:
<Image Source="{StaticResource leftImage}" />
我还尝试在用户控件中加载ResourceDictionary,但这并没有实现。
知道我在这里做错了什么吗?
我将ResourceDictiony更改为:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<BitmapImage x:Key="leftImage" UriSource="/MyApp.Infrastructure;Component/Images/left.png" />
<BitmapImage x:Key="errorImage" UriSource="/MyApp.Infrastructure;Component/Images/error.png" />
</ResourceDictionary>
似乎在MyApp中搜索了图像,因为我在app.xaml中加载了资源字典。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句