返回首页

您好,

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

下面是代码

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

    xmlnsBig Grin | :-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#代码是

{C}

谢谢

回答

评论会员:S 时间:2