Reputation: 43
Looking at the Mahapps project, there is a resource dictionaty (Controls.xaml) that is shown as the "root" of other resource dictionaries in the Solution explorer. How can this be achieved?
The images below show the Controls.xaml item retracted And Extended with some of the resources dictionaries that are merged into the Contorls.xaml file.
Upvotes: 2
Views: 581
Reputation: 398
If you look in the MahApps.Metro.NET45.csproj project file you will find:
<Page Include="Styles\Controls.AnimatedSingleRowTabControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<DependentUpon>Controls.xaml</DependentUpon>
</Page>
And similarly for the other nested xaml resources.
If you have a look in Controls.xaml you will see they use a ResourceDictionary.MergedDictionaries to merge some of the nested xaml resources into Controls.xaml like so:
<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" />
etc...
I'm not sure why they don't merge all the nested xaml controls into Controls.xaml.
I don't think there is a way to add the DependentUpon xml node in the Visual Studio IDE, I added in manually and got the following result. There are addins that claim to add this functionality in the IDE (I didn't try them).
Note that MSDN describes the DependentUpon node as: Optional string. Specifies the file this file depends on to compile correctly. I am not sure if this has a material impact on the compile process.
In conclusion, if you want a visual representation in the IDE of which files rely on each other add the DependentUpon Xml node in the csproj file. If you also want to merge the Resource Dictionaries, use ResourceDictionary.MergedDictionaries in the xaml.
Upvotes: 2