With all of the blog posts about Button styling in WPF since its release, it amazes me that there is very little out there about totally removing the Button default styling. I needed an image to be my button, but without overriding the control template for the button, you can’t remove the borders or get rid of the bluish mouse over effects. Below is a style for a borderless button, whose mouse over and IsPressed effect is a small size transformation to the content.
Borderless Button Style
- <Style x:Key="BorderlessButton" TargetType="{x:Type Button}">
- <Setter Property="Padding" Value="1"/>
- <Setter Property="Background" Value="Transparent" />
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type Button}">
- <Border Name="border" Background="{TemplateBinding Background}">
- <ContentPresenter Name="content" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
- Margin="{TemplateBinding Padding}"
- RecognizesAccessKey="True"
- SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
- VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
- </Border>
- <ControlTemplate.Triggers>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter TargetName="content" Property="RenderTransform" >
- <Setter.Value>
- <ScaleTransform ScaleX="1.1" ScaleY="1.1" />
- </Setter.Value>
- </Setter>
- </Trigger>
- <Trigger Property="IsPressed" Value="True">
- <Setter TargetName="content" Property="RenderTransform" >
- <Setter.Value>
- <ScaleTransform ScaleX=".95" ScaleY=".95" />
- </Setter.Value>
- </Setter>
- </Trigger>
- <Trigger Property="IsFocused" Value="True">
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
Pingback: Windows Client Developer Roundup 058 for 2/7/2011 - Pete Brown's 10rem.net
Pingback: Windows Client Developer Roundup 058 for 2/7/2011 · All About Computer
Hi! I’m very new to WPF. It would be nice if you also display the screenshot of the button using this style