C# 将资源字典文件分组到一个资源字典文件下

C# 将资源字典文件分组到一个资源字典文件下,c#,wpf,visual-studio,xaml,C#,Wpf,Visual Studio,Xaml,查看Mahapps项目,有一个资源字典(Controls.xaml),在解决方案资源管理器中显示为其他资源字典的“根”。如何做到这一点 下图显示了Controls.xaml项,该项使用合并到Contorls.xaml文件中的一些资源字典进行了缩回和扩展 如果查看MahApps.Metro.NET45.csproj项目文件,您会发现: <Page Include="Styles\Controls.AnimatedSingleRowTabControl.xaml"> <Sub

查看Mahapps项目,有一个资源字典(Controls.xaml),在解决方案资源管理器中显示为其他资源字典的“根”。如何做到这一点

下图显示了Controls.xaml项,该项使用合并到Contorls.xaml文件中的一些资源字典进行了缩回和扩展


如果查看MahApps.Metro.NET45.csproj项目文件,您会发现:

<Page Include="Styles\Controls.AnimatedSingleRowTabControl.xaml">
  <SubType>Designer</SubType>
  <Generator>MSBuild:Compile</Generator>
  <DependentUpon>Controls.xaml</DependentUpon>
</Page>

设计师
MSBuild:编译
控件.xaml
对于其他嵌套的xaml资源也是如此

如果查看Controls.xaml,您将看到它们使用将一些嵌套的xaml资源合并到Controls.xaml中,如下所示:

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Sizes.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.Page.xaml" />        
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/ValidationErrorTemplate.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.Scrollbars.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.ListView.xaml" />

等等

我不确定他们为什么不将所有嵌套的xaml控件合并到controls.xaml中

我认为没有办法在VisualStudioIDE中添加DependentUpon xml节点,我手动添加了该节点,得到了以下结果。有人声称要在IDE中添加此功能(我没有尝试过)。

请注意,将DependentUpon节点描述为:可选字符串。指定此文件正确编译所依赖的文件。我不确定这是否对编译过程有重大影响

总之,如果您希望在IDE中可视化表示哪些文件相互依赖,请在csproj文件中添加DependentUpon Xml节点。如果还希望合并资源字典,请在xaml中使用ResourceDictionary.MergedDictionaries