0

我对这些项目有一个解决方案:

1. Clinica (Type is Windows Application),(MainWindow.xaml在这里)

2. Ferhad.Wpf.Core(类型为类库),(共有三个文件:Resources.xaml, OrangeResource.xaml, BlueResource.xaml

Resources.xaml看起来像这样:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Ferhad.Wpf.Core;component/BlueResource.xaml"/>
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

现在,从MainWindow.xaml.cs 我想清除并添加OrangeReource.xamlResources.xaml.

我该怎么做:到目前为止,我已经尝试过:

string fileName = "pack://application:,,,/Ferhad.Wpf.Core;component/OrangeReSource.xaml";
if (System.IO.File.Exists(fileName))
{
    using (FileStream fs = new FileStream(fileName, FileMode.Open))
    {
        ResourceDictionary dic = (ResourceDictionary)XamlReader.Load(fs);

        string fileNameR = "pack://application:,,,/Ferhad.Wpf.Core;component/Resources.xaml";
        if (System.IO.File.Exists(fileNameR))
        {
            using (FileStream fsR = new FileStream(fileNameR, FileMode.Open))
            {
                ResourceDictionary dicR = (ResourceDictionary)XamlReader.Load(fsR);
                dicR.MergedDictionaries.Clear();
                dicR.MergedDictionaries.Add(dic);
            }
        }
    }
}

谢谢。

4

1 回答 1

0

我做了这样的工作:

  var rDictionary = new ResourceDictionary();
  rDictionary.Source = new Uri(string.Format("pack://application:,,,/Ferhad.Wpf.SystemStyles;component/OStyles.xaml"), UriKind.Absolute);
  this.Resources.MergedDictionaries.Add(rDictionary);
于 2012-11-26T12:58:03.707 回答