合并资源字典访问

时间:2016-06-20 08:11:52

标签: c# xaml dll

我有一个使用ResourceDisctionary的本地化dll,如

<ResourceDictionary
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:cultures="clr-namespace:My_Localization.Cultures"
   xmlns:properties="clr-namespace:My_Localization.Properties">

   <ObjectDataProvider x:Key="Resources" ObjectType="{x:Type cultures:CultureResources}" MethodName="GetResourceInstance"/>

</ResourceDictionary>

在另一个dll中,我将此资源字典添加到

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/My Localization;component/ResourcesDict.xaml"/>
        </ResourceDictionary.MergedDictionaries>

        <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
    </ResourceDictionary>

</Window.Resources>

在我的本地化dll中我有一个属性

private static ObjectDataProvider m_provider;
public static ObjectDataProvider ResourceProvider
{
    get
      {
       if (m_provider == null)
         // crashes here
           m_provider =(ObjectDataProvider)Application.Current.FindResource("Resources");
       return m_provider;
      }
   }

当我尝试访问此属性时,我的应用程序崩溃了。我得到以下异常:

  

对象引用未设置为对象的实例(Application.current为null)

任何人都可以帮忙,为什么我的dll找不到资源?

0 个答案:

没有答案
相关问题