3

I haven't found anything similiar to this on Stack or Google, so maybe it isnt' possible, but hopefully someone smart will have an idea. I'm a bit of a noobie to WPF/XAML.

I have a custom class that resembles something similiar to this.

public class LogEntry
{
   public Diciontary<string, string> Stuff;
   public string MyOtherProperty;   
}

My GridView will have 2 columns. One for MyOtherProperty and one for Stuff["Stuff1"]. Assuming I cannot change the Diciontary to something a lot easier to bind to.

I am binding my ListView to a List<LogEntry>. How would I accomplish it in this scenario.

<ListView ItemsSource="{Binding}" DataContext="{Binding}">
   <ListView.View>
      <GridView>
         <GridView.Columns>
            <GridViewColumn DisplayMemberBinding="{Binding MyOtherProperty}"></GridViewColumn>
            <GridViewColumn DisplayMemberBinding="**{Binding Stuff[Stuff1]}**"></GridViewColumn>
         </GridView.Columns>
      </GridView>
   </ListView.View>
</ListView>

Any ideas? Thanks.

scottheckel
  • 9,106
  • 1
  • 35
  • 47

1 Answers1

4

WPF supports binding to properties and not fields. Change LogEntry class to below and it should work.

public class LogEntry
{
    public Dictionary<string, string> Stuff { get; set; }
    public string MyOtherProperty { get; set; }
}
Wallstreet Programmer
  • 9,567
  • 3
  • 37
  • 52