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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:41:11+00:00 2026-05-12T18:41:11+00:00

Hi does anyone know if there are any inbuilt classes for resolving a bound

  • 0

Hi does anyone know if there are any inbuilt classes for resolving a bound object from a bindingexpression and it’s DataItem and property path?

I’m attempting to write a Blend 3 behavior for textboxes which automatically invokes methods on an object bound to the textbox Text property.

The textbox is bound to a property on a viewmodel class. What I want to do is resolve the viewmodel class from the binding expression and then make calls on this.

I first retrieve the binding expression from the behavior’s associated object like so:

private BindingExpression GetTextBinding()
{
    return this.AssociatedObject.GetBindingExpression(TextBox.TextProperty);
}

Having done this, if we look at the binding expression, we can see it has a reference to the data context via the binding expression’s DataItem property.

In addition, we have the relative path of the property which is bound on the binding expression’s parent binding.

So, we can get this information:

var bindingExpression = GetTextBinding();
object dataContextItem = bindingExpression.DataItem;
PropertyPath relativePropertyPath = bindingExpression.ParentBinding.Path;

Now, this property path could potentially be a deeply nested and complex path, which I would very much like to avoid having to (re?)implement resolution of. I’ve searched around the .NET documentation and bounced around the assemblies with reflector, all to no avail – I can’t find what surely must exist – there’s got to be some class which performs the resolution of the path for the dataitem (the data context).

Does anyone know where this might exist? Any suggestions for alternative ways of resolving the bound object?

Note, I’m trying to get at the bound object which is the parent of the bound property (the string in this case) – I can obviously easily get at the bound value, but it’s the parent I need.

Thanks in advance for any help!
Phil

  • 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-12T18:41:12+00:00Added an answer on May 12, 2026 at 6:41 pm

    Below is a quick implementation for an extension method that will do just what you are looking for. I couldn’t find anything related to this either. The method below will always return null if for some reason the value cannot be found. The method won’t work when the path includes []. I hope this helps!

    public static T GetValue<T>(this BindingExpression expression, object dataItem)            
    {
        if (expression == null || dataItem == null)
        {
            return default(T);
        }
    
        string bindingPath = expression.ParentBinding.Path.Path;
        string[] properties = bindingPath.Split('.');
    
        object currentObject = dataItem;
        Type currentType = null;
    
        for (int i = 0; i < properties.Length; i++)
        {
            currentType = currentObject.GetType();                
            PropertyInfo property = currentType.GetProperty(properties[i]);
            if (property == null)
            {                    
                currentObject = null;
                break;
            }
            currentObject = property.GetValue(currentObject, null);
            if (currentObject == null)
            {
                break;
            }
        }
    
        return (T)currentObject;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 403k
  • Answers 403k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm fairly certain this can't be done. You might be… May 15, 2026 at 5:19 am
  • Editorial Team
    Editorial Team added an answer Use the All tab in the NET panel POST parameters… May 15, 2026 at 5:19 am
  • Editorial Team
    Editorial Team added an answer I would recommend using the Archive::Zip module rather than the… May 15, 2026 at 5:19 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.