question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Window Button Style

See original GitHub issue

Describe the bug

Here are some findings, when I try to put buttons in resource dictionary for the window:

  1. when i try to use the system command like below, the window button cannot be clicked anymore (double clike, the window will be maximized or normalized)
<Setter Property="Command"
 			Value="{Binding Source={x:Static SystemCommands.MinimizeWindowCommand}}" />
  1. I try to apply the style below to window button, the IsPressed trigger works as expected, but the IsMouseOver trigger doesn’t work
	<Style x:Key="WindowTitleButtonStyle"
	       TargetType="{x:Type Button}">
		<Setter Property="Focusable"
			Value="False" />
		<Setter Property="Background"
			Value="#32FFFFFF" />		
		<Setter Property="Width"
			Value="36" />
		<Setter Property="HorizontalContentAlignment"
			Value="Center" />
		<Setter Property="VerticalContentAlignment"
			Value="Center" />
		<!--<Setter Property="WindowChrome.IsHitTestVisibleInChrome"
			Value="True" />-->
		<Setter Property="IsTabStop"
			Value="False" />
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type Button}">
					<Grid x:Name="LayoutRoot"
					      Background="Transparent">
						<Rectangle x:Name="ButtonBackground"
							   Fill="Yellow"
							   Opacity="0" />
						<Border x:Name="ButtonBorder"
							SnapsToDevicePixels="True">
							<ContentPresenter x:Name="TitileButtonContentPresenter"
									  Focusable="False" 
									  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
									  Margin="{TemplateBinding Padding}"
									  RecognizesAccessKey="True"
									  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
									  VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
						</Border>
					</Grid>

					<ControlTemplate.Triggers>
						<Trigger Property="IsMouseOver"
							 Value="True">
							<Setter Property="Opacity"
								Value="1"
								TargetName="ButtonBackground" />
						</Trigger>
						<Trigger Property="IsPressed"
							 Value="True">
							<Setter Property="Opacity"
								Value="0.6"
								TargetName="ButtonBackground" />
						</Trigger>
						<Trigger Property="IsEnabled"
							 Value="False">
							<Setter TargetName="TitileButtonContentPresenter"
								Property="Opacity"
								Value="0.5" />
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

and here are codes for applying the styles:

<UniformGrid Grid.Column="2"
						Columns="3">
	<Button Content=" - "
		Style="{StaticResource PART_WindowButtonMinimizeStyle}"
		tcBehaviors:NonClientControlProperties.HitTestResult="MINBUTTON"
		tcBehaviors:NonClientControlProperties.ClickStrategy="MouseEvent" />
	<Button Style="{StaticResource PART_WindowButtonMaximizeStyle}"
		IsEnabled="{Binding IsEnabled, ElementName=MaximizeButton}"
		tcBehaviors:NonClientControlProperties.HitTestResult="MAXBUTTON"
		tcBehaviors:NonClientControlProperties.ClickStrategy="MouseEvent" />
	<Button  Style="{StaticResource WindowTitleButtonStyle}"
		tcBehaviors:NonClientControlProperties.HitTestResult="CLOSE"
		tcBehaviors:NonClientControlProperties.ClickStrategy="MouseEvent" />
</UniformGrid>

It is acceptable for me to give up the system command. What I can try to fix the mouseover problem?

Thanks, Tiger

Steps to reproduce

Expected behavior

Actual behavior

Environment

ControlzEx version: v6.x.x
Windows build number: Win11
Visual Studio: 2022
Target Framework: .Net 4.8

Screenshots

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

Button Styles (Winuser.h) - Win32 apps
Specifies a combination of button styles. If you create a button using the BUTTON class with the CreateWindow or CreateWindowEx function, ...
Read more >
Other Window Styles for Button Controls
The following window style options are available for button controls (check box, radio button group, push button, and group box controls).
Read more >
Windows Buttons
windows buttons design in CSS with hover and click effect...
Read more >
Windows OS Button Style CSS
It's quite difficult to style a button exactly like that, and in a usable scalable format. An alternative is to simulate an HTML...
Read more >
How to change Windows 10 button style?
How to change button style like on the higher pic? Mine is on lower pic. Its much cleaner and edges are thinner.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found