简体   繁体   中英

how to override WPF Theme style for a single button

I succesfully apply a theme to my WPF app.

Now I need a specific button to style in a totally different way but I cannot override what the theme applies.

How can this be done?

Create two styles. One you already create for all buttons in your application. Now create another style but put the key attribute to it and assign it to your specific buttons.

In your App.xaml:

<Style TargetType="{x:Type Button}"> <!-- This is for generic button -->
    <Setter Property="FontSize" Value="12"/>
</Style>  

Now its time for your specific button:

<Style TargetType="{x:Type Button}" x:Key="specificButton"> <!-- This is for specific button -->
    <Setter Property="FontSize" Value="20"/>
</Style>  

In your Page or UserControl:

<Button Width="200" Height="50" VerticalAlignment="Top" Margin="0,20,0,0" />
<Button Style="{StaticResource specificButton}" Width="200" Height="50" VerticalAlignment="Top" Margin="0,20,0,0" />  

Hope it helps.

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