【问题标题】:How to get at ResourceDictionary style when it is loaded from external xap and assemblies are MEF-fed?从外部 xap 加载 ResourceDictionary 样式并且程序集是 MEF 馈送时,如何获得 ResourceDictionary 样式?
【发布时间】:2011-03-03 00:51:57
【问题描述】:

我有以下设置:

主应用程序加载一个带有 IPlugin 实现的 XAP。该插件包含一个“DisplayPanel”,其中包含一个引用的控件和其他控件。这里的 DisplayPanel 只是一个容器控件,用于显示引用的 Control。

来自程序集的此引用控件使用此程序集中的 ResourceDictionary xaml 中的样式。至少这是我想要的。问题是引用的Control抛出错误:

找不到名称/密钥 PlayerPanelGrad [行:1500 的资源 位置:127]

我已尝试通过 Merged Resource 字典引用引用 theResourceDictionary 来获得样式:

       <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="TableControls;component/ControlsStyle.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

但这不起作用。

你会如何处理这个?

【问题讨论】:

    标签: silverlight assemblies mef resourcedictionary xap


    【解决方案1】:

    为了将来参考,我的 XAML 文件位于需要 / 字符的解决方案的子目录中,但文件位于其中名为 Assets 的子目录中。

    <ResourceDictionary 
         Source="/MyAssemblyName;component/Assets/RadResources.xaml" />
    

    此外,.XAML 文件在解决方案中构建为 Page

    【讨论】:

      【解决方案2】:

      //先动态加载other.dll,然后使用如下代码:

             StreamResourceInfo srf = Application.GetResourceStream(new Uri("otherdll;component/Resources/Brush.xaml", UriKind.Relative));
      
              StreamReader sr = new StreamReader(srf.Stream);
              string stt = sr.ReadToEnd();
              ResourceDictionary dict = XamlReader.Load(stt) as ResourceDictionary;
              Application.Current.Resources.MergedDictionaries.Add(dict);
      

      【讨论】:

        【解决方案3】:

        这个问题可能会有所帮助,但老实说,我仍在尝试自己弄清楚: Using MEF to import a WPF DataTemplate?

        【讨论】:

          【解决方案4】:

          我让它工作的唯一方法是在 InitializeComponent 调用之前以编程方式将资源字典加载到控件中(在类库中):

          public ActionPanel()
          {
               StreamResourceInfo sr = Application.GetResourceStream(
                    new Uri("TableControls;component/ControlsStyle.xaml", UriKind.Relative));
               Application.Current.Resources.Add("plop",sr.Stream);
               // Required to initialize variables
               InitializeComponent();
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-04-27
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-03-03
            相关资源
            最近更新 更多