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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:04:38+00:00 2026-05-23T23:04:38+00:00

I have a Grid control where each row contains a stackpanel, and each stackpanel

  • 0

I have a Grid control where each row contains a stackpanel, and each stackpanel contains one or more textblocks (while not the core of the question, if there’s a better way to achieve a custom grid of textblocks – i.e. rows of “header label: content”, I’d appreciate some tips)

Anyway… I want to have a header row, where the stackpanel has a dark background and the textblock has white, bold text, and then each other row to have black text. Note that only the first row is defined with Style HeaderRow. I’ve used the “BasedOn” to define that only textblocks within a header row should be bold/white, however I’m finding that this impacts all textblocks in other rows too (that don’t have another style defined).

I’d effectively like to be able to do

Sample XAML

Styles:

 <Style x:Key="TitleLabel" TargetType="TextBlock">
                    <Setter Property="FontFamily" Value="Verdana"/>
                    <Setter Property="Margin" Value="5 0 0 0"/>
                    <Setter Property="Width" Value="105"/>
                    <Setter Property="FontWeight" Value="Bold"/>
                </Style>
                <Style x:Key="AlternatingRow" TargetType="StackPanel">
                    <Setter Property="Background" Value="#f0f1ff"/>
                </Style>
                <Style x:Key="HeaderRow" TargetType="StackPanel">
                    <Setter Property="Background" Value="#666666"/>
                </Style>
                <Style TargetType="TextBlock" BasedOn="StaticResource HeaderRow" >
                    <Setter Property="Foreground" Value="White"/>
                    <Setter Property="FontWeight" Value="Bold"/>
                </Style>

XAML

<Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                    </Grid.RowDefinitions>
                    <StackPanel Orientation="Horizontal" Grid.Row="0" Style="{StaticResource HeaderRow}">
                        <TextBlock Text="Header Row" />
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Grid.Row="1" Style="{StaticResource AlternatingRow}">
                        <TextBlock Text="HeaderLabel:" Style="{StaticResource TitleLabel}" />
                        <TextBlock Text="Content" />
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Grid.Row="2">
                        <TextBlock Text="HeaderLabel"  Style="{StaticResource TitleLabel}" />
                        <TextBlock Text="Content" />
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Grid.Row="3" Style="{StaticResource AlternatingRow}">
                        <TextBlock Text="HeaderLabel"  Style="{StaticResource TitleLabel}" />
                        <TextBlock Text="Content" />
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Grid.Row="4">
                        <TextBlock Text="HeaderLabel"  Style="{StaticResource TitleLabel}" />
                        <TextBlock Text="Content" />
                    </StackPanel>
                </Grid>
  • 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-23T23:04:40+00:00Added an answer on May 23, 2026 at 11:04 pm

    You are not using Style BasedOn property correctly. All it does is indicate that one style ‘extends’ another, i.e. it copies all its setter values. (Note, your example will also fail because you are trying to base on style on another where the TargetTypes are not compatible) It does not indicate that a style is applied when one element is nested inside another.

    Unfortunately Silverlight does not have the feature you require, you cannot style based on element location within the visual tree. You are going to have to style each TextBlock explicitly.

    Although, I did create a mechanism for using CSS for styling a while back:

    http://www.scottlogic.co.uk/blog/colin/2009/03/using-css-selectors-for-styling-in-wpf/

    This allows you to create selectors based on parent elements.

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

Sidebar

Related Questions

I have a gridview control with delete asp:ImageButton for each row of the grid.
Suppose I have a grid with some row definitions, and a child control in
I have a window with 2 column grid. Left column contains a browser control
I have a parent grid that contains multiple row definitions, all of which have
Here's the scenario I have a Grid with some TextBlock controls, each in a
I have a Data Grid View inside a control that is displayed in a
How to implement CEditListCtrl?. List control with edit capabality (Report/Grid view). I have a
I have two different grid controls on the same form. They share the same
I have a problem. I need to host grid with controls in ScrollViewer to
I have a grid laid out like so; +---------+---------+ | Image | Details |

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.