我正在动态加载 aResourceDictionary
并将其添加到MergedDictionaries
如下所示:
var mergedDictionaries = Resources.MergedDictionaries;
mergedDictionaries.Clear();
// Generic styles
ResourceDictionary vsStyles = new ResourceDictionary();
vsStyles.Source = new Uri("pack://application:,,,/AssemblyName;component/VSTheme/VSStyles.xaml");
mergedDictionaries.Add(vsStyles);
// Theme-dependent styles
ResourceDictionary bright = new ResourceDictionary();
bright.Source = new Uri("pack://application:,,,/AssemblyName;component/Images/Bright.xaml");
mergedDictionaries.Add(bright);
Bright.xaml 如下所示:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<BitmapImage UriSource="..\Images\Bright\folder-bright.png" x:Key="FolderItemImage" />
<BitmapImage UriSource="..\Images\Bright\class-bright.png" x:Key="ClassItemImage" />
(...)
</ResourceDictionary>
这些图像正在 UI 中显示的树视图项中使用:
<Image x:Name="iIcon" Width="16" Height="16" Margin="0, 1, 3, 1" Source="{DynamicResource FolderItemImage}"/>
通常,它们显示没有问题,但是当我运行程序时(尽管图像显示正确),我收到很多警告:
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='NativeImage'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='ClassItemImage'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='NativeImage'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='ClassItemImage'
为什么会这样?