Search code examples
c#wpflistviewmodel-view

How can I link a ListView to ModelView?


I want to create a ListView with the names and the codes of the products in my ModelView but when I do:

<ListView ItemsSource="{Binding Path=Products}" 
SelectedValue="{Binding Path=Product}" />

Only the Product Guids are showed.

How could I create a column with the Product.Name property and another onew with the Product.Code property?


Solution

  • Use a GridView. Perhaps like this:

    <ListView ItemsSource="{Binding Products}">
      <ListView.View>
        <GridView>
          <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
          <GridViewColumn Header="Code" DisplayMemberBinding="{Binding Code}"/>
        </GridView>
      </ListView.View>
    </ListView>