Click here to Skip to main content
16,019,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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-

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



And the c# code is-

C#
{
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
Posted
Updated 16-Sep-11 2:10am
v2

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900