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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:33:57+00:00 2026-05-12T20:33:57+00:00

Today, I was working on a WPF UserControl to display the current value of

  • 0

Today, I was working on a WPF UserControl to display the current value of a few variables. I was wondering if there would be a way to make a super simple property grid in WPF. The problem is on the starred line of the XAML below. How would I bind a string to a property with an ItemTemplate like I have setup below? To be more clear can I embed bindings inside of one another {Binding Path={Binding Value}}.

Here is the class:

public class Food
{
    public string Apple { get; set; }
    public string Orange { get; set; }
    public IEnumerable<KeyValuePair<string, string>> Fields
    {
        get
        {
            yield return new KeyValuePair<string, string>("Apple Label", "Apple");
            yield return new KeyValuePair<string, string>("Orange Label", "Orange");
        }
    }
}

And here is the XAML:

<UserControl x:Class="MAAD.Plugins.FRACTIL.Simulation.SimulationStateView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="331" Width="553">
 <ListView ItemSource="{Binding Fields}">
  <ListView.ItemTemplate>
   <DataTemplate>
    <StackPanel Orientation="Horizontal">
     <TextBlock Text="{Binding Key}" />
     **<TextBlock Text="{Binding Path={Binding Value}}" />**
    </StackPanel>
   </DataTemplate>
  </ListView.ItemTemplate>
 </ListView>
</UserControl>
  • 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-12T20:33:58+00:00Added an answer on May 12, 2026 at 8:33 pm

    The essence of the problem is that you need not just the list of field descriptions and names, but the actual object that has those fields and names.

    You can use a converter like that adds target references to the field objects and provides a value accessor, like this:

      public class PropertyValueAccessConverter : IMultiValueConverter
      {
        object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
          var target = values[0];
          var fieldList = values[1] as IEnumerable<KeyValuePair<string,string>>;
          return
            from pair in fieldList
            select new PropertyAccessor
            {
              Name = pair.Name,
              Target = target,
              Value = target.GetType().GetProperty(target.Value),
            };
        }
    
        object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
          throw new InvalidOperationException();
        }
    
        public class PropertyAccessor
        {
          public string Name
          public object Target;
          public PropertyInfo Property;
    
          public object Value
          {
            get { return Property.GetValue(Target, null); }
            set { Property.SetValue(Target, value, null); }
          }
        }
    
        public static PropertyValueAccessConverter Instance = new PropertyValueAccessConverter();
      }
    

    With this converter you can bind your ItemsSource like this:

      <ListView>
        <ListView.ItemsSource>
          <MultiBinding Converter="{x:Static local:PropertyValueAccessConverter.Instance}">
            <Binding />
            <Binding Path="Fields" />
          </MultiBinding>
        </ListView.ItemsSource>
      </ListView>
    

    By the way, a much more efficient way to implement your Fields property is:

      public IEnumerable<KeyValuePair<string, string>> Fields
      {
        get
        {
          return new KeyValuePair<string, string>[]
          {
            new KeyValuePair<string, string>("Apple Label", "Apple");
            new KeyValuePair<string, string>("Orange Label", "Orange");
          }
        }
      }
    

    Though frankly I would use description attributes on the individual properties along with reflection instead of hard-coding the list. That would also eliminate the need for the MultiBinding in the first place.

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

Sidebar

Related Questions

Brains not working today and can't find a nice way of doing this. So
I'm not sure why this isn't working today, I've done very similar a few
I was working on a WPF project today that had a main nav window
Brain not working today - can anyone give me a regexp that would turn:
On the Nerd Plus Art blog today, there was a post about creating WPF
I was working today and decided to start using JQUERY to make a toggle
Brain totally not working today. So, I have a few columns in a table
today I started working with DirectX(D3D9), everything went fine until I created a Static-mesh
Today i started working in registration form in magento site. As you know by
Today I'm working with an interesting problem. I'm trying to code simple bookmarks, and

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.