2014-11-04 94 views
2

查看Mahapps项目,资源dictionaty(Controls.xaml)显示为解决方案资源管理器中其他资源字典的“根”。这怎么能实现?在一个资源字典文件下分组资源字典文件

下面的图像显示Controls.xaml项目已收回并扩展了一些合并到Contorls.xaml文件中的资源字典。

enter image description here

enter image description here

回答

2

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

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

而且类似的其他嵌套的XAML资源。

如果您在Controls.xaml看看,你会看到他们使用ResourceDictionary.MergedDictionaries一些嵌套的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中。

我不认为有一种方法可以在Visual Studio IDE中添加DependentUpon xml节点,我手动添加并获得以下结果。有addins声称在IDE中添加此功能(我没有尝试它们)。
enter image description here

请注意,MSDN将DependentUpon节点描述为:可选字符串。 指定此文件依赖于正确编译的文件。我不确定这是否会对编译过程产生重大影响。总之,如果你想要在IDE中使用可视化表示方式,在其中文件相互依赖,请在csproj文件中添加DependentUpon Xml节点。如果您还想合并资源字典,请使用xaml中的ResourceDictionary.MergedDictionaries。