2012-11-14 62 views
2

我试图让我的应用程序(WPF)使用引用的程序集在我的App.xaml使用的Pack URI。在我的解决方案中,我有几个项目。在基本应用程序中,我只有我的App.xaml。我希望这个使用引用程序集。C#的App.xaml和资源字典

叫我基地项目与项目的App.xaml 1(溶液)。这是App.xaml的相关部分:

<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="pack://application:,,,/MyProject.Project2;component/Themes/Generic.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 

项目2有一个Generic.xaml文件夹“主题”。我很确定我正在使用Pack URI,因为没有使用Generic.xaml中的样式(我正在使用自定义窗口覆盖默认窗口,但它目前不工作。默认窗口样式,窗口内的所有内容都是黑色的)。

文件夹层次结构:

MainFolder 
    Project 1 
     App.xaml 
     bin 
      Debug 
       Application.exe 
    Project 2 
     Themes 
      Generic.xaml 

问题:

  1. 有人能解释pack://application:,,,语法?这一切意味着什么?
  2. 我在做什么错的包URI?

在此先感谢。

+0

从MSDN包URI在WPF按照此 - http://msdn.microsoft.com/en-us/library/aa970069.aspx –

+0

@ RV1987我已经这样做了,这里的代码或多或少直接从该页面中拉出。 – tnw

回答

1

想通了。原来在MyProject.Project2我需要的AssemblyInfo.cs以下代码:

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 
//(used if a resource is not found in the page, 
// or application resource dictionaries) 
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 
//(used if a resource is not found in the page, 
// app, or any theme specific resource dictionaries) 
)] 
1

的,,,后在包URI的第一项是组件的名称。请确保您设置:

"pack://application:,,,/[ASSEMBLY name here];component/Themes/Generic.xaml"

+0

是的,程序集名称设置正确。 – tnw

1

尝试将资源字典到项目2,而不是在App.xaml中。