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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:08:25+00:00 2026-05-25T13:08:25+00:00

Consider the following, simple code: XAML: <Grid Height=60 Name=grid> <Grid.ColumnDefinitions> <ColumnDefinition Width=162* /> <ColumnDefinition

  • 0

Consider the following, simple code:


XAML:

<Grid Height="60" Name="grid">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="162*" />
        <ColumnDefinition x:Name="coltest" Width="316*" />
        <ColumnDefinition Width="239*" />
    </Grid.ColumnDefinitions>
</Grid>
<Label MouseDoubleClick="TextBox_MouseDoubleClick" 
    Content="{Binding ElementName=coltest, Path=ActualWidth}" Grid.Row="1"/>

The MouseDoubleClick event:

private void TextBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    grid.RowDefinitions.Add(new RowDefinition());
    for (int i = 0; i < grid.ColumnDefinitions.Count; i++)
    {
        Random r = new Random();
        Label l = new Label { Content = r.Next(10, 1000000000).ToString() };
        grid.Children.Add(l);
        Grid.SetRow(l, grid.RowDefinitions.Count - 1);
        Grid.SetColumn(l, i);
    }
}

My label contains the ActualWidth property of the second column via a binding. In Visual Studio I see my label containing the value 316, so the binding works.

Double clicking the label triggers its event and adds an extra row to the grid, all with a random length.

I expect to see a new value at my label, but (the at runtime calculated) 0 does not change!

What am I missing here?

  • 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-25T13:08:26+00:00Added an answer on May 25, 2026 at 1:08 pm

    The main problem is that ActualWidth of a ColumnDefinition isn’t a Dependency Property, nor does it implement INotifyPropertyChanged so the Binding has no way of knowing that the ActualWidth of coltest has changed.

    You’ll need to explicitly update the Binding

    Edit2: In this case, you might be able to update the Binding in the SizeChanged event for the Grid since the Columns have * width. This won’t work 100% with Auto width though since the width will change based on the elements in the ColumnDefinition

    <Grid Name="grid"
          SizeChanged="grid_SizeChanged">
        <!--...-->
    </Grid>
    

    Event handler

    void grid_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        BindingExpression be = label.GetBindingExpression(Label.ContentProperty);
        be.UpdateTarget();
    }
    

    Edit: Made some small changes to the Xaml. This will update the Binding everytime you doubleclick the first Label

    <Grid Name="grid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="162*" />
            <ColumnDefinition x:Name="coltest" Width="316*" />
            <ColumnDefinition Width="239*" />
            <ColumnDefinition Width="239*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Label MouseDoubleClick="TextBox_MouseDoubleClick"
               Name="label"
               Content="{Binding ElementName=coltest, Path=ActualWidth}" Grid.Row="0"/>
    </Grid>
    

    Event handler

    private void TextBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        grid.RowDefinitions.Add(new RowDefinition());
        for (int i = 0; i < grid.ColumnDefinitions.Count; i++)
        {
            Random r = new Random();
            Label l = new Label { Content = r.Next(10, 1000000000).ToString() };
            grid.Children.Add(l);
            Grid.SetRow(l, grid.RowDefinitions.Count - 1);
            Grid.SetColumn(l, i);
        }
        BindingExpression be = label.GetBindingExpression(Label.ContentProperty);
        be.UpdateTarget();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following example code: http://code.google.com/apis/maps/documentation/javascript/examples/streetview-simple.html I can do scrollwheel: false on a mapOptions
Consider the following simple code to create a typesafe equals. This first section allows
Consider the following simple python code >>> L = range(3) >>> L [0, 1,
Please consider the following code implementing a simple MixIn : class Story(object): def __init__(self,
Please consider the following code implementing a simple MixIn : class Story(object): def __init__(self,
Consider the following simple code: List <?> list4[] = { Arrays.asList(1,2), Arrays.asList(1,2)}; I do
I would like to ask probably simple question. Consider following php page: <p>Name of
Consider the following code: $(.lcontainer a).click(function () { var current = $(this); var name
Consider the following simple code pattern: foreach(Item item in itemList) { if(item.Foo) { DoStuff(item);
Consider the following simple code import java.util.*; public class MainTest<T extends Object1<?,?>> { List<T>

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.