Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF将主题应用于特定项目,而不是整个应用程序_Wpf_C# 4.0_Mvvm - Fatal编程技术网

WPF将主题应用于特定项目,而不是整个应用程序

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" />

我在project1中创建了一个主题,并在app.xaml中引用了theme.xaml。其效果是所有项目在解决方案中获得相同的主题

将theme.xaml应用于指定项目(即仅应用于project1而不应用于project2)的最简单方法是什么

我知道我可以使用

    <Window.Resources>
        <ResourceDictionary Source="/Project1;component/Themes/Customized.xaml" />
    </Window.Resources>

但是,如果我想改变项目的主题,这就有点难以维持了。我要寻找的是类似project.xaml的东西,其行为类似于app.xaml,只是范围是当前项目。这样,我就可以在一个地方为指定的项目(而不是其他项目)引用theme.xaml

可能吗

提前谢谢

  • 创建一个项目主题资源字典,并将对
    FooTheme.xaml的引用放入其中

  • 在项目的所有窗口中,将引用放入
    ProjectTheme.xaml

  • 这样,为了更改项目的主题,您只需要修改一行

    代码:

    FooTheme.xaml(示例主题)

    
    
    项目主题.xaml(项目主题)

    
    
    MainWindow.xaml(示例项目窗口)

    
    
  • 创建一个项目主题资源字典,并将对
    FooTheme.xaml的引用放入其中

  • 在项目的所有窗口中,将引用放入
    ProjectTheme.xaml

  • 这样,为了更改项目的主题,您只需要修改一行

    代码:

    FooTheme.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>