With the latest VS update, custom window min/max/exit buttons no longer display UI behavior

Jose Fernandez 1 Reputation point
2021-09-20T19:40:39.95+00:00

Hi All,
I have a custom window style for WPF netcore. The title bar buttons are drawn but with the latest VS update the mouseover doesn't produce the desired effect. For example, when hover over the exit button, it should set the button background to a red color. After the update only mousing over the bottom 2 or 3 px of the button will trigger the red, but when you mouse over the middle of the button, the red is gone. Below are the styles:

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:foundation="clr-namespace:PMA.Foundation"
xmlns:res="clr-namespace:PMA.Foundation.Properties">

<SolidColorBrush x:Key="MouseOverOverlayBackgroundBrush" Color="#33000000" />
<SolidColorBrush x:Key="PressedOverlayBackgroundBrush" Color="#44000000" />
<SolidColorBrush x:Key="MouseOverWindowCloseButtonBackgroundBrush" Color="Firebrick" />
<SolidColorBrush x:Key="PressedWindowCloseButtonBackgroundBrush" Color="Firebrick" />
<DropShadowEffect x:Key="NetPointWindowDropShadowEffect" BlurRadius="6" Direction="270" RenderingBias="Quality" ShadowDepth="3" Opacity=".16"/>
<SolidColorBrush x:Key="NetPointBrush" Color="White" PresentationOptions:Freeze="True"/>
<SolidColorBrush x:Key="NetPointTextBrush" Color="Gray" PresentationOptions:Freeze="True"/>

<SolidColorBrush x:Key="NetPointDisabledButtonTextBrush"  PresentationOptions:Freeze="True">
    <SolidColorBrush.Color>
        <Color A="#FF" R="150" G="150" B="150" />
    </SolidColorBrush.Color>
</SolidColorBrush>

<Style x:Key="TitleBarButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Foreground" Value="{StaticResource NetPointTextBrush}" />
    <Setter Property="Padding" Value="0" />
    <Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="RenderOptions.EdgeMode" Value="Aliased" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border x:Name="border"
                        Background="Transparent"
                        BorderThickness="0"
                        SnapsToDevicePixels="true">
                    <ContentPresenter x:Name="contentPresenter"
                                      Margin="0"
                                      HorizontalAlignment="Center"
                                      VerticalAlignment="Center"
                                      Focusable="False"
                                      RecognizesAccessKey="True" />
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter TargetName="border" Property="Background" Value="{DynamicResource MouseOverOverlayBackgroundBrush}" />
                    </Trigger>
                    <Trigger Property="IsPressed" Value="true">
                        <Setter TargetName="border" Property="Background" Value="{DynamicResource PressedOverlayBackgroundBrush}" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style x:Key="TitleBarCloseButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Foreground" Value="{StaticResource NetPointTextBrush}" />
    <Setter Property="Padding" Value="0" />
    <Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="RenderOptions.EdgeMode" Value="Aliased" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border x:Name="border"
                        Background="Transparent"
                        BorderThickness="0"
                        SnapsToDevicePixels="true">
                    <ContentPresenter x:Name="contentPresenter"
                                      Margin="0"
                                      HorizontalAlignment="Center"
                                      VerticalAlignment="Center"
                                      Focusable="False"
                                      RecognizesAccessKey="True" />
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter TargetName="border" Property="Background" Value="{DynamicResource MouseOverWindowCloseButtonBackgroundBrush}" />
                        <Setter Property="Foreground" Value="White" />
                    </Trigger>
                    <Trigger Property="IsPressed" Value="true">
                        <Setter TargetName="border" Property="Background" Value="{DynamicResource PressedWindowCloseButtonBackgroundBrush}" />
                        <Setter Property="Foreground" Value="White" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style x:Key="TitleBarPathStyle" TargetType="{x:Type Path}">
    <Setter Property="Width" Value="46" />
    <Setter Property="Height" Value="32" />
    <Setter Property="Stroke" Value="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}" />
    <Setter Property="StrokeThickness" Value="1" />
</Style>

<Style x:Key="CustomWindowsStyle" TargetType="{x:Type Window}">
    <Setter Property="FontFamily" Value="{StaticResource FontAssistant}"/>
    <Setter Property="shell:WindowChrome.WindowChrome">
        <Setter.Value>
            <shell:WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}"/>
        </Setter.Value>
    </Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Window}">
                <Border x:Name="OuterBorder"
                        BorderBrush="{x:Static SystemColors.WindowFrameBrush}"
                        BorderThickness="1">
                    <Grid Background="{StaticResource NetPointBrush}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Border x:Name="InnerBorder" 
                                Grid.RowSpan="2"
                                Margin="{Binding Source={x:Static shell:SystemParameters.WindowNonClientFrameThickness}}" 
                                Padding="0,6,0,0">
                            <ContentPresenter Content="{TemplateBinding Content}" 
                                              Margin="-3,2,-3,-3"/>
                        </Border>
                        <Border x:Name="titleBarBorder" 
                                BorderThickness="0"
                                Background="{StaticResource NetPointBrush}"
                                Effect="{StaticResource NetPointWindowDropShadowEffect}"/>
                        <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}"
                                   VerticalAlignment="Top" 
                                   HorizontalAlignment="Center"
                                   Focusable="False"
                                   Margin="0,8,0,0"
                                   FontSize="12"
                                   Foreground="{StaticResource NetPointTextBrush}"
                                   TextAlignment="Center"
                                   TextWrapping="NoWrap"/>
                        <StackPanel Orientation="Horizontal"
                                    HorizontalAlignment="Right"
                                    VerticalAlignment="Top">
                            <Button x:Name="MinimizeButton"
                                    Command="{Binding Path=WindowBarCommandHandler, RelativeSource={RelativeSource AncestorType=Window}}"
                                    CommandParameter="Min"
                                    ToolTip="{x:Static res:Resources.string_Minimize}"
                                    Style="{StaticResource TitleBarButtonStyle}">
                                <Path Style="{StaticResource TitleBarPathStyle}"
                                      Data="M 18,15 H 28" />
                            </Button>
                            <Button x:Name="MaxButton"
                                    Command="{Binding Path=WindowBarCommandHandler, RelativeSource={RelativeSource AncestorType=Window}}"
                                    CommandParameter="Max"
                                    ToolTip="{x:Static res:Resources.string_Maximize}"
                                    Style="{StaticResource TitleBarButtonStyle}">
                                <Path Style="{StaticResource TitleBarPathStyle}"
                                      Data="M 18.5,10.5 H 27.5 V 19.5 H 18.5 Z" />
                            </Button>
                            <Button x:Name="NormalButton" 
                                    Command="{Binding Path=WindowBarCommandHandler, RelativeSource={RelativeSource AncestorType=Window}}"
                                    CommandParameter="Normal"
                                    ToolTip="{x:Static res:Resources.string_RestoreDown}"
                                    Style="{StaticResource TitleBarButtonStyle}">
                                <Path Style="{StaticResource TitleBarPathStyle}"
                                      Data="M 18.5,12.5 H 25.5 V 19.5 H 18.5 Z M 20.5,12.5 V 10.5 H 27.5 V 17.5 H 25.5" />
                            </Button>
                            <Button x:Name="CloseButton"
                                    Command="{Binding Path=WindowBarCommandHandler, RelativeSource={RelativeSource AncestorType=Window}}"
                                    CommandParameter="Exit"
                                    ToolTip="{x:Static res:Resources.string_Close}"
                                    Style="{StaticResource TitleBarCloseButtonStyle}">
                                <Path Style="{StaticResource TitleBarPathStyle}"
                                      StrokeThickness="1.5"
                                      StrokeEndLineCap="Round"
                                      StrokeStartLineCap="Round"
                                      Data="M 18,11 L 27,20 M 18,20 L 27,11" />
                            </Button>
                        </StackPanel>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="WindowState" Value="Maximized">
                        <Setter TargetName="MaxButton" Property="Visibility" Value="Collapsed" />
                        <Setter TargetName="NormalButton" Property="Visibility" Value="Visible" />
                        <Setter TargetName="OuterBorder" Property="Border.BorderThickness" Value="6" />
                    </Trigger>
                    <Trigger Property="WindowState" Value="Normal">
                        <Setter TargetName="MaxButton" Property="Visibility" Value="Visible" />
                        <Setter TargetName="NormalButton" Property="Visibility" Value="Collapsed" />
                        <Setter TargetName="OuterBorder" Property="Border.BorderThickness" Value="1" />
                    </Trigger>
                    <Trigger Property="IsActive" Value="False">
                        <Setter TargetName="MinimizeButton" Property="Foreground" Value="{StaticResource NetPointDisabledButtonTextBrush}" />
                        <Setter TargetName="MaxButton" Property="Foreground" Value="{StaticResource NetPointDisabledButtonTextBrush}" />
                        <Setter TargetName="NormalButton" Property="Foreground" Value="{StaticResource NetPointDisabledButtonTextBrush}" />
                        <Setter TargetName="CloseButton" Property="Foreground" Value="{StaticResource NetPointDisabledButtonTextBrush}" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

</ResourceDictionary>

<Window x:Class="PMA.Summit.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PMA.Summit"
mc:Ignorable="d"
Style="{DynamicResource CustomWindowsStyle}"
Title="Hello"
Height="720"
MinHeight="720"
Width="900"
MinWidth="900"
WindowStartupLocation="CenterScreen">
<Grid>
</Grid>
</Window>

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,647 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,109 questions
{count} votes