Reputation: 5260
I created a theme in my project1 and referenced the theme.xaml in the app.xaml. the effect is the all projects gets the same theme within the solution.
What is the simplest way to apply a theme.xaml to a specified project, i.e. only to project1 but not project2?
I know I can reference the theme.xaml in each WFP form within project1 using
<Window.Resources>
<ResourceDictionary Source="/Project1;component/Themes/Customized.xaml" />
</Window.Resources>
But that is a little bit hard to maintain if I want to change the theme for the project. What I am looking for is something like project.xaml that behave like app.xaml, only the scope is to the current project. that way I can reference the theme.xaml in one place for the specified project (but not other projects).
Is that possible?
Thanks in advance.
Upvotes: 1
Views: 1059
Reputation: 34285
Create a project theme resource dictionary and put reference to FooTheme.xaml
into it.
In all your windows of the project, put reference to ProjectTheme.xaml
.
This way, in order to change the theme of the project, you'll need to modify only one line.
Code:
FooTheme.xaml (sample theme)
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="Button">
<Setter Property="Background" Value="Blue"/>
</Style>
</ResourceDictionary>
ProjectTheme.xaml (project theme)
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<!-- In order to modify the project's theme, change this line -->
<ResourceDictionary Source="FooTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
MainWindow.xaml (sample project window)
<Window x:Class="So17372811ProjectTheme.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ProjectTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Button Content="Click me!"/>
</Grid>
</Window>
Upvotes: 1