我在project1中创建了一个主题,并在app.xaml中引用了theme.xaml。效果是所有项目在解决方案中都有相同的主题。
将theme.xaml应用于指定项目的最简单方法是什么,即只应用于project1而不应用于project2?
我知道我可以在project1中的每个世界粮食计划署表单中引用theme.xaml
<Window.Resources>
<ResourceDictionary Source="/Project1;component/Themes/Customized.xaml" />
</Window.Resources>但是,如果我想改变项目的主题,这就有点难以维护了。我正在寻找的是像project.xaml一样的东西,行为像app.xaml,只有范围是当前的项目。这样,我就可以在一个地方为指定的项目(而不是其他项目)引用theme.xaml。
这有可能吗?
提前谢谢。
发布于 2013-06-29 14:30:45
FooTheme.xaml的引用放入其中。在项目的所有窗口中,将对FooTheme.xaml的引用放入这样,为了更改项目的主题,您将只需要修改一行。
代码:
FooTheme.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>ProjectTheme.xaml (项目主题)
<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 (示例项目窗口)
<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>https://stackoverflow.com/questions/17372811
复制相似问题