WPF将主题应用于特定项目,而不是整个应用程序
我在project1中创建了一个主题,并在app.xaml中引用了theme.xaml。其效果是所有项目在解决方案中获得相同的主题 将theme.xaml应用于指定项目(即仅应用于project1而不应用于project2)的最简单方法是什么 我知道我可以使用WPF将主题应用于特定项目,而不是整个应用程序,wpf,c#-4.0,mvvm,Wpf,C# 4.0,Mvvm,我在project1中创建了一个主题,并在app.xaml中引用了theme.xaml。其效果是所有项目在解决方案中获得相同的主题 将theme.xaml应用于指定项目(即仅应用于project1而不应用于project2)的最简单方法是什么 我知道我可以使用 <Window.Resources> <ResourceDictionary Source="/Project1;component/Themes/Customized.xaml" />
<Window.Resources>
<ResourceDictionary Source="/Project1;component/Themes/Customized.xaml" />
</Window.Resources>
但是,如果我想改变项目的主题,这就有点难以维持了。我要寻找的是类似project.xaml的东西,其行为类似于app.xaml,只是范围是当前项目。这样,我就可以在一个地方为指定的项目(而不是其他项目)引用theme.xaml
可能吗
提前谢谢
FooTheme.xaml的引用放入其中
ProjectTheme.xaml
项目主题.xaml(项目主题)
MainWindow.xaml(示例项目窗口)
FooTheme.xaml的引用放入其中
ProjectTheme.xaml
项目主题.xaml(项目主题)
MainWindow.xaml(示例项目窗口)
非常好。非常感谢你的帮助,太好了。非常感谢你的帮助。
<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>
<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>
<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>