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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:29:15+00:00 2026-05-16T20:29:15+00:00

My question is about properly binding the property of one element to another. Here

  • 0

My question is about properly binding the property of one element to another.

Here is the structure of my code:

  1. Data Template contains a grid (let’s called the grid GridA), and in the grid, I specify an instance of a control, called ControlA.

  2. ControlA is a UserControl that contains a Grid. There is custom logic in ControlA (code-behind) that dynamically builds the content – but in a nutshell, it uses another data template.

  3. The data template for ControlA consists of another Grid. I want to bind the Height property for this grid in this data template to the Height property of the Grid in the data template referenced in my first bullet point above (the grid called GridA).

Here is the XAML that I have used for the binding, but, essentially, it isnt working, as its not finding the Grid:

<Grid Height="{Binding Path=ActualHeight,
                       RelativeSource={RelativeSource FindAncestor,
                                       AncestorType=Grid,
                                       AncestorLevel=2},
                       UpdateSourceTrigger=PropertyChanged}">
</Grid>

I understand that by specifying AncestorLevel=2, that it will use the second “found” occurrence of the type that you are looking for, in this case, the type is Grid. So in my mind, it will first find the Grid in ControlA, then it will continue to walk up the tree and find the Grid in the first data template, which is the Grid named GridA. This should be the second occurrence, correct?

  • 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-16T20:29:16+00:00Added an answer on May 16, 2026 at 8:29 pm

    Since you’re beginning your search from the second grid, you actually want ancestor level = 1 (which is the default). Observe:

    <Grid x:Name="first">
        <Grid x:Name="second">
            <Grid x:Name="third" Tag="{Binding Name, RelativeSource={RelativeSource FindAncestor, AncestorType=Grid, AncestorLevel=2}}">
                <!-- displays "first", not "second" -->
                <TextBlock Text="{Binding Tag, ElementName=third}"/>
            </Grid>
        </Grid>
    </Grid>
    

    BTW, your design sounds like it fights WPF’s layout system rather than embracing it. As such, you’re probably creating a lot of unnecessary pain for yourself.

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

Sidebar

Related Questions

I have another question about binding using C# and the entity framework. Here, I'm
I have a question about data binding in WP7 using c# code. If I
I have a question about data binding which I am struggling with. I have
In a related question I asked about binding to a particular element of an
Question about logics here: What's the most elegant way to make the menu appear/disappear
one question about PHP Development. I am building up some Form Fields for Calculations.
This question is similar to another one I asked , but whereas in that
I have a doubt about binding to an ancestor property in WPF. My situation
This question looks like this one : Programmatically binding List to ListBox but as
Several answers to questions about check box binding, for example this one suggest that

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.