Search code examples
wpfbuttonflat

Create flat button in WPF


How to make a button flat style in wpf? I've tried BasedOn property but it does not work.


Solution

  • Just to get you started:

    <Page
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Page.Resources>
        <Style x:Key="Flat">
            <Setter Property="Control.Background" Value="{x:Null}" />
            <Setter Property="Control.BorderBrush" Value="{x:Null}" />
            <Style.Triggers>
                <Trigger Property="Control.IsMouseOver" Value="True">
                    <Setter Property="Control.Background" Value="{x:Null}" />
                    <Setter Property="Control.BorderBrush" Value="{x:Null}" />
                    <Setter Property="Control.FontWeight" Value="Bold" />
                </Trigger>
                <Trigger Property="Control.IsFocused" Value="True">
                    <Setter Property="Control.FontWeight" Value="Bold" />
                </Trigger>
            </Style.Triggers>
        </Style>
      </Page.Resources>
      <StackPanel>  
        <Button Style="{StaticResource Flat}">Hello</Button>
      </StackPanel>
    </Page>
    

    Then you have one millon other ways to do it, even changing the ControlTemplate to complete redefine the Button