Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>You can use a converter like that adds target references to the field objects and provides a value accessor, like this:</p> <pre><code> public class PropertyValueAccessConverter : IMultiValueConverter { object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { var target = values[0]; var fieldList = values[1] as IEnumerable&lt;KeyValuePair&lt;string,string&gt;&gt;; 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(); } </code></pre> <p>With this converter you can bind your ItemsSource like this:</p> <pre><code> &lt;ListView&gt; &lt;ListView.ItemsSource&gt; &lt;MultiBinding Converter="{x:Static local:PropertyValueAccessConverter.Instance}"&gt; &lt;Binding /&gt; &lt;Binding Path="Fields" /&gt; &lt;/MultiBinding&gt; &lt;/ListView.ItemsSource&gt; &lt;/ListView&gt; </code></pre> <p>By the way, a much more efficient way to implement your Fields property is:</p> <pre><code> public IEnumerable&lt;KeyValuePair&lt;string, string&gt;&gt; Fields { get { return new KeyValuePair&lt;string, string&gt;[] { new KeyValuePair&lt;string, string&gt;("Apple Label", "Apple"); new KeyValuePair&lt;string, string&gt;("Orange Label", "Orange"); } } } </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload