Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 63599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:39:28+00:00 2026-05-10T18:39:28+00:00

In WPF, how would I apply multiple styles to a FrameworkElement ? For instance,

  • 0

In WPF, how would I apply multiple styles to a FrameworkElement? For instance, I have a control which already has a style. I also have a separate style which I would like to add to it without blowing away the first one. The styles have different TargetTypes, so I can’t just extend one with the other.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:39:29+00:00Added an answer on May 10, 2026 at 6:39 pm

    I think the simple answer is that you can’t do (at least in this version of WPF) what you are trying to do.

    That is, for any particular element only one Style can be applied.

    However, as others have stated above, maybe you can use BasedOn to help you out. Check out the following piece of loose xaml. In it you will see that I have a base style that is setting a property that exists on the base class of the element that I want to apply two styles to. And, in the second style which is based on the base style, I set another property.

    So, the idea here … is if you can somehow separate the properties that you want to set … according the inheritance hierarchy of the element you want to set multiple styles on … you might have a workaround.

    <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">     <Page.Resources>         <Style x:Key="baseStyle" TargetType="FrameworkElement">             <Setter Property="HorizontalAlignment" Value="Left"/>         </Style>         <Style TargetType="Button" BasedOn="{StaticResource baseStyle}">             <Setter Property="Content" Value="Hello World"/>         </Style>     </Page.Resources>     <Grid>         <Button Width="200" Height="50"/>     </Grid> </Page> 

    Note:

    One thing in particular to note. If you change the TargetType in the second style (in first set of xaml above) to ButtonBase, the two Styles do not get applied. However, check out the following xaml below to get around that restriction. Basically, it means you need to give the Style a key and reference it with that key.

    <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">     <Page.Resources>         <Style x:Key="baseStyle" TargetType="FrameworkElement">             <Setter Property="HorizontalAlignment" Value="Left"/>         </Style>         <Style x:Key="derivedStyle" TargetType="ButtonBase" BasedOn="{StaticResource baseStyle}">             <Setter Property="Content" Value="Hello World"/>         </Style>     </Page.Resources>     <Grid>         <Button Width="200" Height="50" Style="{StaticResource derivedStyle}"/>     </Grid> </Page> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What would be the best WPF control in C# (VS 2008) that you can
In WPF 3.5 (with SP1), I have simply StackPanel that I would like to
Considering you have an MVVM Architecture in WPF like Josh Smith's examples How would
I want to extend a WPF application with database functionality. Which database engine would
I'm using the built-in SpellCheck for the WPF RichTextBox and would like to ignore
What would be the bast way to change the orientation of the WPF treeview.
i`m currently playing around with WPF and now i wonder what would be the
I am following the M-V-VM pattern for my WPF UI. I would like to
What is the difference between a BitmapFrame and BitmapImage in WPF? Where would you
I am working on an interactive WPF graph/tree tool and have nodes and links

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.