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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:22:01+00:00 2026-05-11T15:22:01+00:00

I’m trying to bind a TextBlock’s Text property in a very dynamic way. I

  • 0

I’m trying to bind a TextBlock’s Text property in a very dynamic way. I need to get the Path from an underlying object.

Here’s the DataTemplate:

<DataTemplate DataType={x:Type local:DummyClass}>   <TextBlock Text={Binding Path=???} /> </DataTemplate> 

The DummyClass object has a property named ‘FieldValuePath’ – the path that needs to be put where the ??? is.

The idea behind this is that the data template is supposed to be a GUI for viewing/editing any property of any object. So it’s kind of preferable to be able to declare XAML which would bind some controls (textboxes, textblocks, datepickers, etc) to a given property.

Maybe anyone has any suggestions on how to implement such thing?

  • 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. 2026-05-11T15:22:02+00:00Added an answer on May 11, 2026 at 3:22 pm

    If you create the binding in the code behind then you could get it to work. For example a simple code generated binding is:

    Binding binding = new Binding('BindingPath'); binding.Mode = BindingMode.TwoWay; BindingOperations.SetBinding(textBoxName, TextBox.TextProperty, binding); 

    Since the path in this binding (‘BindingPath’) is just a string, that string could come from any available object.

    You’ll need to hook into the creation of your data items to set these binding though.


    A further possibility based on your comments:

    This blog post outlines a way to create a custom binding class by inheriting from MarkupExtension. You may be able to use this as a starting point to wrap my suggestion into a reusable xaml markup for your special binding case.


    More thoughts:

    Okay, this was an interesting problem, so I decided to spend a little time seeing if I could come up with a working solution. I apologise in advance for the length of the following code samples…

    Basing my solution on the blog post I linked to above I created this class:

    public class IndirectBinder : MarkupExtension     {         public string IndirectProperty { get; set; }          public override object ProvideValue(IServiceProvider serviceProvider)         {             //try to get bound items for our custom work             DependencyObject targetObject;             DependencyProperty targetProperty;             bool status = TryGetTargetItems(serviceProvider, out targetObject, out targetProperty);              if (status)             {                 Control targetControl = targetObject as Control;                 if (targetControl == null) return null;                  //Find the object to take the binding from                 object dataContext = targetControl.DataContext;                 if (dataContext == null) return null;                  //Reflect out the indirect property and get the value                 PropertyInfo pi = dataContext.GetType().GetProperty(IndirectProperty);                 if (pi == null) return null;                  string realProperty = pi.GetValue(dataContext, null) as string;                 if (realProperty == null) return null;                  //Create the binding against the inner property                 Binding binding = new Binding(realProperty);                 binding.Mode = BindingMode.TwoWay;                 BindingOperations.SetBinding(targetObject, targetProperty, binding);                  //Return the initial value of the binding                 PropertyInfo realPi = dataContext.GetType().GetProperty(realProperty);                 if (realPi == null) return null;                  return realPi.GetValue(dataContext, null);              }              return null;          }          protected virtual bool TryGetTargetItems(IServiceProvider provider, out DependencyObject target, out DependencyProperty dp)         {             target = null;             dp = null;             if (provider == null) return false;              //create a binding and assign it to the target             IProvideValueTarget service = (IProvideValueTarget)provider.GetService(typeof(IProvideValueTarget));             if (service == null) return false;              //we need dependency objects / properties             target = service.TargetObject as DependencyObject;             dp = service.TargetProperty as DependencyProperty;             return target != null && dp != null;         } 

    You can use this new markup with the following xaml:

    <TextBox Text='{local:IndirectBinder IndirectProperty=FieldValuePath}'/> 

    Where TextBox can be any class that inherits from control and Text can be any dependency property.

    Obviously if you need to expose any of the other databinding options (such as one or two way binding) then you’ll need to add more properties to the class.

    While this is a complicated solution, one advantage that it has over using a converter is that the binding that is finally created is against the actual inner property rather than the object. This means that it correctly reacts to PropertyChanged events.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters

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.