C# 关于不存在资源的警告,WPF

C# 关于不存在资源的警告,WPF,c#,wpf,dynamicresource,C#,Wpf,Dynamicresource,我正在动态加载一个ResourceDictionary,并将其添加到MergedDictionaries中,如下所示: var mergedDictionaries = Resources.MergedDictionaries; mergedDictionaries.Clear(); // Generic styles ResourceDictionary vsStyles = new ResourceDictionary(); vsStyles.Source = ne

我正在动态加载一个
ResourceDictionary
,并将其添加到
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);
<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>
Bright.xaml如下所示:

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);
<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>

为什么会这样?

这些错误可能发生在
ResourceDictionary
加载之前。。。一旦装载完毕,他们会停止吗?如果是这样的话,你可以忽略它们。。。毕竟,它们只是警告

我在
Binding
s中也遇到过类似的情况,但是有一个
Binding.IsAsync
属性,我可以设置它,告诉
Binding
值不会立即出现。这使得警告消失了。不幸的是,我认为
资源
没有类似的属性,所以你可能不得不接受它,或者尝试更早地加载你的
资源字典。

类似的问题几年前在中得到了“回答”

不幸的是,“回答”意味着这是一个WPF的问题,微软还没有解决