在WPF中窗口形式的主题没有改变 [英] Theme of window form is not changing in wpf

查看:52
本文介绍了在WPF中窗口形式的主题没有改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用Microsoft.window.shell.dll修改了标题栏,准备了wpf窗口应用程序,但是当我们更改系统主题时,我项目的标题栏变成黑色.谁能帮我解决这个问题.

代码如下-

Hi,

I prepared the wpf window application using Microsoft.window.shell.dll to modify the title bar but when we change the theme of the system the the title bar of my project become black . Can anyone help me to solve this problem.

The code is below-

<Window x:Class="Hello.Window1" xml:lang="en-US"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"

    xmlns:Hello="clr-namespace:Hello"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2006"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    xmlns:local="clr-namespace:Hellow"

    x:Name="Window"

    Title="Hello"

    MinHeight="100"

    MinWidth="200" SizeChanged="Window_SizeChanged"

    Height="635" Width="955" Loaded="Window_Loaded"

    ResizeMode="CanResize" WindowStartupLocation="CenterScreen" Icon="/Hello;component/graphics/Menu.gif" PreviewKeyDown="Window_PreviewKeyDown" MouseLeftButtonDown="Window_MouseDown"

     >
    <Window.CommandBindings>
        <CommandBinding Command="{x:Static shell:SystemCommands.CloseWindowCommand}"

                    Executed="_OnSystemCommandCloseWindow"/>
    </Window.CommandBindings>
    <Window.Resources>
        <Style x:Key="GlassStyle" TargetType="{x:Type local:Window1}">
            <Setter Property="shell:WindowChrome.WindowChrome">
                <Setter.Value>
                    <shell:WindowChrome GlassFrameThickness="-1" ResizeBorderThickness="6" CaptionHeight="40" CornerRadius="6,0,6,20" />
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:Window1}">
                        <Grid>
                            <Border BorderThickness="3" BorderBrush="#3b5998" CornerRadius="8,8,8,8" Background="Transparent">
                                <ContentPresenter Margin="6,26,6,6" Content="{TemplateBinding Content}"/>
                            </Border>
                            <ContentPresenter

                  Margin="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowNonClientFrameThickness}" Content="{TemplateBinding Content}"/>
                            <Button shell:WindowChrome.IsHitTestVisibleInChrome="True" VerticalAlignment="Top"  HorizontalAlignment="Left" Style="{StaticResource GlassButton}"

                                Margin="15,5,4,6" Width="40" Height="40"

                                Padding="8">
                                <Button.ContextMenu>
                                    <ContextMenu>
                                        <MenuItem Name="create_send_log" Header="Create and send log file" Click="create_send_log_Click" FontFamily="Tahoma" Background="{DynamicResource TitleBorderBrush}" />
                                        <MenuItem Name="logMenu" Header="Create Log File" Click="CreateLogClick" FontFamily="Tahoma" Background="{DynamicResource TitleBorderBrush}" />
                                        <MenuItem Header="About" Click="AboutClick" FontFamily="Tahoma" Background="{DynamicResource TitleBorderBrush}" />
                                    </ContextMenu>
                                </Button.ContextMenu>
                                <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Icon}" Width="40" Height="40" Stretch="Uniform" />
                            </Button>
                        </Grid>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="GradientStyle" TargetType="{x:Type local:Window1}">
            <Setter Property="shell:WindowChrome.WindowChrome">
                <Setter.Value>
                    <shell:WindowChrome

            ResizeBorderThickness="6"

            CaptionHeight="40"

            CornerRadius="6,0,6,20"

            GlassFrameThickness="0"/>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:Window1}">
                        <Grid>
                            <Border BorderThickness="6" BorderBrush="#3b5998">
                                <Border.Background>
                                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,50" MappingMode="Absolute">
                                        <GradientStop Offset="0" Color="#8b9dc3"/>
                                        <GradientStop Offset="1" Color="#3b5998"/>
                                    </LinearGradientBrush>
                                </Border.Background>
                                <ContentPresenter Margin="6,26,6,6" Content="{TemplateBinding Content}"/>
                            </Border>
                            <Button shell:WindowChrome.IsHitTestVisibleInChrome="True"

                  VerticalAlignment="Top"

                  HorizontalAlignment="Left"

                  Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(shell:WindowChrome.WindowChrome).ResizeBorderThickness}"

                  Padding="10">
                                <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Icon}" Width="32" Height="32"/>
                            </Button>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
            <Grid x:Name="LayoutRoot">




C#代码是-




And the c# code is-

{
var style = (Style)Resources["GlassStyle"];
           this.Style = style;
       }
       private void _OnStandardChromeClicked(object sender, RoutedEventArgs e)
       {
           this.Style = null;
       }

       private void _OnGradientChromeClicked(object sender, RoutedEventArgs e)
       {
           var style = (Style)Resources["GradientStyle"];
           this.Style = style;
       }

       private void _OnGlassyChromeClicked(object sender, RoutedEventArgs e)
       {
           var style = (Style)Resources["GlassStyle"];
           this.Style = style;
       }

       private void _OnSystemCommandCloseWindow(object sender, ExecutedRoutedEventArgs e)
       {
           SystemCommands.CloseWindow((Window)e.Parameter);
       }





谢谢





Thanks

推荐答案


这篇关于在WPF中窗口形式的主题没有改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆