Transparent button background in WPF using style

Bilow picture Bilow · Jan 16, 2014 · Viewed 21.8k times · Source

I've found this topic about setting the border of a button to transparent. This works fine, but I want to use this for the button background and not the border.

Solution in link which I've put in <Window.Resources>...</Window.Resources>:

<Style TargetType="{x:Type Button}">
    <Setter Property="Background" Value="Green"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border Background="{TemplateBinding Background}">
                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="Red"/>
        </Trigger>
    </Style.Triggers>
</Style>

Source: How do you change Background for a Button MouseOver in WPF?

How can edit this code so I can use this to set the background of my button to transparent and not the border of it?

Answer

aDoubleSo picture aDoubleSo · Jan 16, 2014

Try this snippet for a transparent button:

<Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" BorderThickness="0">
    <-- PUT BUTTON CONTENT HERE e.g. a Image -->
</Button>