1

I am wanting to just set the title bar and border of a WPF window but the title background property doesn't look to be exposed in the class.

I want to leave all default Window behavior and just set the color property of Title Bar and Border

What is the correct property to set?

I am refrencing: https://learn.microsoft.com/en-us/dotnet/api/system.windows.shell.windowchrome?view=netframework-4.7.2

      <ResourceDictionary>
        <Style x:Key="CustomWindowStyle" TargetType="{x:Type Window}">
            <Setter Property="WindowChrome.WindowChrome">
                <Setter.Value>
                    <WindowChrome/>
                </Setter.Value>
            </Setter>
            <Setter Property="??" Value="Blue"/>
        </Style>
    </ResourceDictionary>

The only property I see is the Title Property and setting its color has no effect

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Matt
  • 500
  • 7
  • 18
  • possible duplicate of https://stackoverflow.com/questions/1283006/changing-wpf-title-bar-background-color – Daniel Feb 08 '19 at 00:23
  • @Daniel I saw that post but was looking to something specific to WindowChrome and .net 4.7.2 functionality - the examples in that post reconstruct the window itself. – Matt Feb 08 '19 at 00:30

1 Answers1

2

So I resolved this and it was more involved then I had originally thought. Since the title bar is in the non-client area when editing it I would lose the visibility of the corner buttons.

In the end I had to reconstruct the title bar and create a class to implement the buttons to get the look I desired.

This will give you a window with a border and the title bar will also have a color. You need to implement the corner buttons though.

   xmlns:shell="http://schemas.microsoft.com/netfx/2009/xaml/presentation"
   <Style x:Key="StandardStyle" TargetType="{x:Type Window}">
                <Setter Property="shell:WindowChrome.WindowChrome">
                    <Setter.Value>
                        <shell:WindowChrome 
                              />
                    </Setter.Value>
                </Setter>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Window}" >
                            <Grid>
                                <!--Title Panel-->
                                <DockPanel LastChildFill="True">
                                    <Border Background="Blue" DockPanel.Dock="Top" 
                                    Height="{x:Static SystemParameters.CaptionHeight}" x:Name="titlebar">
                                        <Grid>
 <!--Title text only-->
                                            <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" 
                                VerticalAlignment="Top" HorizontalAlignment="Center" Background="Transparent"  />
                                            <usercontrols:CornerButtons HorizontalAlignment="Right"/>
                                        </Grid>

                                    </Border>
                                    <!--Provides the actual content control-->
                                    <Border Margin="0,0,0,0"  >
                                        <AdornerDecorator>
                                            <ContentPresenter Content="{TemplateBinding Content}"/>
                                        </AdornerDecorator>
                                    </Border>
                                </DockPanel>

                                 <!--Provides the actual window border-->
                                <Border 
                                        Margin="0,0,0,0"
                                        Background="White"
                                        Grid.ZIndex="-1"
                                        BorderThickness="2,2,2,2" BorderBrush="Blue"
                                       >
                                </Border>                              

                                <!--This is the top left system button-->
                                <!--<Button
                                Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(shell:WindowChrome.WindowChrome).ResizeBorderThickness}"
                                Padding="1"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Top"
                                shell:WindowChrome.IsHitTestVisibleInChrome="True"
                                Command="{x:Static shell:SystemCommands.ShowSystemMenuCommand}"
                                CommandParameter="{Binding ElementName=CalcWindow}">
                                    <Image
                                    Width="16"
                                    Height="16"
                                    shell:WindowChrome.IsHitTestVisibleInChrome="True"
                                    Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Icon}" />
                                </Button>-->
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
Matt
  • 500
  • 7
  • 18