简体   繁体   中英

Make WPF button look less flat

I've got 2 buttons on my form, and they both look very, very flat.

平面按钮

I can't seem to find a way to make them look more like:

不平按钮

The XAML for my buttons is:

<Button x:Name="bttnDailyReport" HorizontalAlignment="Left" Margin="618,27,0,0" VerticalAlignment="Top" Width="121" Height="93" FontFamily="Microsoft Sans Serif" FontSize="20" FontWeight="Bold" Grid.Column="1" BorderBrush="Black">
    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"><Run Text="  Generate"/><LineBreak/><Run Text="Daily Report"/></TextBlock>
</Button>
<Button x:Name="bttnCancel" HorizontalAlignment="Left" Margin="618,126,0,0" VerticalAlignment="Top" Width="121" Height="93" FontFamily="Microsoft Sans Serif" FontSize="20" FontWeight="Bold" Click="BttnCancelClick">
    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"><Run Text="Exit"/></TextBlock>
</Button>

Now, my question is, is it possible to make the buttons appear like the button in WinForms, or am I stuck with flat buttons?

Seems, somewhere in your resources, flat button style is used as default style for button.

Check Styling and Templating . Either you need to override the style in your button, or give key to the default style, and apply wherever needed.

How to override a global style (that doesn't have an x:Key), or alternatively apply a named style to all type-targeted controls?

Just reference PresentationFramework.Aero.dll in your project and add this code to to the window's XAML:

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/PresentationFramework.Aero;component/themes/aero.normalcolor.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

By default, buttons should look like the second image. To make sure that there is no "BoringButton" Style around that make your buttons look flat (as Tilak and Chris W suggest), try to explicitly clear your button's Style like this:

<Button x:Name="bttnDailyReport" Style="{x:Null}" >

Also, don't set your button's Background to a specific color (although that already looks OK in the code you posted).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM