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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:07:17+00:00 2026-05-13T23:07:17+00:00

I’d like to have the nested containers inherit that property, but when I set

  • 0

I’d like to have the nested containers inherit that property, but when I set it in the outermost one I’m not sure if it’s working. It either is working but I’m not getting the results I want, or maybe I’d have to set up a property somewhere for it to carry.

Assuming that a) it is possible to do it and b) I’d have to change a property somewhere, would that have any side effects I should be aware of?

EDIT

Ok, here’s an example:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Test" Width="300" Height="100">
    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" Grid.Column="0">Text</Label>
        <TextBox Grid.Row="0" Grid.Column="1">I'm on the Internet</TextBox>
        <Button Grid.Row="0" Grid.Column="2">Don't click me</Button>
        <Label Grid.Row="1" Grid.Column="0">Text2</Label>
        <Slider Grid.Row="1" Grid.Column="1"></Slider>
        <Button Grid.Row="1" Grid.Column="2">Click the other guy</Button>
    </Grid>
</Window>

What I would like to have, without having to do it manually:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Test" Width="300" Height="100">
    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Label VerticalAlignment="Center" Grid.Row="0" Grid.Column="0">Text</Label>
        <TextBox VerticalAlignment="Center" Grid.Row="0" Grid.Column="1">I'm on the Internet</TextBox>
        <Button VerticalAlignment="Center" Grid.Row="0" Grid.Column="2">Don't click me</Button>
        <Label VerticalAlignment="Center" Grid.Row="1" Grid.Column="0">Text2</Label>
        <Slider VerticalAlignment="Center" Grid.Row="1" Grid.Column="1"></Slider>
        <Button VerticalAlignment="Center" Grid.Row="1" Grid.Column="2">Click the other guy</Button>
    </Grid>
</Window>

Although I’m not really sure there was any difference here. It’s not a deal breaker or anything, but I’d like to do it this way.

  • 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-13T23:07:17+00:00Added an answer on May 13, 2026 at 11:07 pm

    VisualTree inheritance is not universal. The dependency property specifies that it will inherit down the visual tree when it is declared. In this case, verticalalignment is not.

    The only way to get a consistent vertical alignment is to use a style. And you can’t use an implicit style across different types of controls. So you need to create a named style, place it in the resources of the container. Add a setter to the style to set the vertical alignment to whichever value you want. Finally reference the style in all the controls to which you want it applied.

    Here is your example done with styles…unfortunately you’re not saving much typing however if your style did something like Set VerticalAlignment and the FontFamily, then you’re saving space…If you think of it like CSS then WPF Styles are easy.

    <Window x:Class="WpfApplication1.Window1" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        Title="Test" Width="300" Height="100"> 
        <Grid ShowGridLines="True"> 
            <Grid.RowDefinitions> 
                <RowDefinition Height="Auto"/> 
                <RowDefinition Height="Auto"/> 
            </Grid.RowDefinitions> 
            <Grid.ColumnDefinitions> 
                <ColumnDefinition Width="Auto"/> 
                <ColumnDefinition Width="Auto"/> 
                <ColumnDefinition Width="Auto"/> 
            </Grid.ColumnDefinitions> 
            <Grid.Resources>
                <Style x:Key="setVA" TargetType="{x:Type Control}">
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
            </Grid.Resources>
            <Label Style="{StaticResource setVA}" Grid.Row="0" Grid.Column="0">Text</Label> 
            <TextBox Style="{StaticResource setVA}" Grid.Row="0" Grid.Column="1">I'm on the Internet</TextBox> 
            <Button Style="{StaticResource setVA}" Grid.Row="0" Grid.Column="2">Don't click me</Button> 
            <Label Style="{StaticResource setVA}" Grid.Row="1" Grid.Column="0">Text2</Label> 
            <Slider Style="{StaticResource setVA}" Grid.Row="1" Grid.Column="1"></Slider> 
            <Button Style="{StaticResource setVA}" Grid.Row="1" Grid.Column="2">Click the other guy</Button> 
        </Grid> 
    </Window> 
    

    There’s more information on using styles on MSDN

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

Sidebar

Related Questions

I have text I am displaying in SIlverlight that is coming from a CMS
I've got a string that has curly quotes in it. I'd like to replace
I have some data like this: 1 2 3 4 5 9 2 6
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a JSP page retrieving data and when single or double quotes are
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.