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

  • SEARCH
  • Home
  • 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

Ask A Question

Stats

  • Questions 182k
  • Answers 182k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Change line 107 to: PluginDiskstats::~PluginDiskstats() May 12, 2026 at 4:22 pm
  • Editorial Team
    Editorial Team added an answer The suggestion to dynamically alter the DOM is clever, because… May 12, 2026 at 4:22 pm
  • Editorial Team
    Editorial Team added an answer Answering your question strictly, you need to add an extern… May 12, 2026 at 4:22 pm

Related Questions

I have the following scenario: Entities are loaded from the database. One of them
I'm developing an application that needs to perform some processing on the user's Outlook
I need to apply some text formatting when displaying items in a WPF ListView.
In WPF Databinding, I understand that you have DataContext which tells an element what

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.