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 7924701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:52:59+00:00 2026-06-03T17:52:59+00:00

I want to have a default style for all TextBlock controls in my application

  • 0

I want to have a default style for all TextBlock controls in my application that uses the Royal theme. For example:

<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
    <Setter Property="Margin" Value="4"/>        
</Style>

This works great inherited from the Royal theme but unfortunately also affects the style of TextBlock that is used inside the templates of other controls like ComboBox and I don’t want that.

I already tried to place my style one level down (for example inside Grid.Resources) but with no luck.

Is there a way to do that? Of course I don’t want to name my style (using x:key) because I don’t want to have to explicitly apply to each and every TextBlock of my application the custom style. And without creating subclasses for overwriting the style there.

Any ideas? Thank you in advance!

P.S. I already looked at questions that might be similar but no answer there worked for me.

EDIT:

Thanks for all the answers. I hoped there is some way that I miss with which I can distinguish the TextBlock used inside other controls templates.

  • 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. Editorial Team
    Editorial Team
    2026-06-03T17:53:04+00:00Added an answer on June 3, 2026 at 5:53 pm

    By this exclusion:

    Of course I don’t want to name my style (using x:key) because I don’t
    want to apply to each and every TextBlock of my application the custom
    style. And without creating subclasses for overwriting the style
    there.

    you pretty much ask the impossible. The style you created will be applied to all TextBlocks in the visual tree below the dictionary that contains the style.

    If you want to make exceptions you will have to specify them one way or another.

    Apparently your requirement “to have a default style for all TextBlock controls” isn’t true. You do NOT want ALL the TextBlocks to have this style.

    Moving the style one or more levels down could be a solution if you want the style applied from that level on.

    There is no way to specify that you want to apply the style to specific TextBlocks and not to others unless you are able to distinguish between them them in some way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have site wide default settings for all jQuery validation uses on
So I want to have tabs with default style but I want to handle
Hey all, I've noticed that if I have a style setup for a treeview,
Is there a way to select all elements that have a given style using
I have a ScrollBar style in my project that is automatically used by all
I want to be able to have default text like Enter content here... appear
I have a project where I want to have checked arithmetic by default, except
I want to set my GtkComboBox to have some default value/name, on it as
I want to have a ProgressDialog with determinate progress bar instead of default spinner.
MSDTC is disabled by default (windows 2003 - onwards) and I want to have

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.