Global Style in WPF?

Total Post:28


 3420  View(s)
Rate this:

Is there a way to setup global styles for my WPF application?

What I'm hoping to do is apply a style to all my Buttons that also have an Image child.

  1. Re: Global Style in WPF?

    Well, sort of - it's a catch-all approach you can do - put the following element in your App.xaml - all your buttons will change (except the ones you apply a style to, manually).

    <Style TargetType="{x:Type Button}">
        <Setter Property="Background" Value="LightPink"/> <!-- You should notice that one... -->

    However, if you want to hit only buttons with images - you have to inherit from Button everytime you do and then apply a style like this:

    public class CustomImageButton:Button{}
    <Style TargetType="{x:Type local:CustomImageButton}">
        <Setter Property="Background" Value="LimeGreen"/>
    <local:CustomImageButton Content="ClickMe"/>

    It is a very coarse-grained global styling - and you need to follow the convention to make it work.

      Modified On Apr-03-2018 04:54:17 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.