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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:48:37+00:00 2026-05-27T02:48:37+00:00

I have some StackPanels I wish to have the same Width. However this should

  • 0

I have some StackPanels I wish to have the same Width. However this should not affect all StackPanels and I do not want to subclass just for this. I know that the following is possible:

<Style BasedOn="{StaticResource {x:Type TextBlock}}"
    TargetType="TextBlock"
    x:Key="TitleText">
        <Setter Property="FontSize" Value="26"/>
</Style>

...

<TextBlock Style="{StaticResource TitleText}"> 
    Some Text 
</TextBlock>

But is there a way to keep the TextBlock ignorant of its Style (like it is when the
HTML is separate from the CSS rule that applies to the element)?

I would just like to give all the relevant StackPanels the same class id, and then apply
the style to the class id.

  • 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-05-27T02:48:38+00:00Added an answer on May 27, 2026 at 2:48 am

    Unfortunately, this is not possible in WPF. The closest you can come to this is what you’ve demonstrated in your example.

    However, if you want to apply a style to all StackPanels in the same root container, you can specify the Style as a resource of the root container, leaving the x:Key attribute out. As an example:

    <Grid x:Name="LayoutRoot">
        <Grid x:Name="StackPanelsRoot">
            <Grid.Resources>
                <Style TargetType="StackPanel">
                    ...
                </Style>
            </Grid.Resources>
            <StackPanel x:Name="SP1" ... />
            <StackPanel x:Name="SP2" ... />
            ...
        </Grid>
        <StackPanel x:Name="SP3" ... />
        ...
    </Grid>
    

    Here, the Style will be applied to SP1 and SP2, but not to SP3

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

Sidebar

Related Questions

I want to have some output like this where the width of column1 is
I have some ASP.NET web services which all share a common helper class they
I have some classes layed out like this class A { public virtual void
I have some code like this in a winforms app I was writing to
I have some kind of test data and want to create a unit test
I have some controls added in a stackpanel programmatically. What i want to do
I have some xaml pasted at the end of this question. It's from a
I have some images that I want to display with a watermark. Currently they
I am using C# and WPF and I basically want to have some toggle
Lets say I have some XAML like this: <StackPanel> <TextBlock Text=Blah Blah Blah />

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.