Reputation: 111
I have a small listview and want to display data from a list of objects in it. The object has another object, whos data should be displayed too. The code looks like this.
XAML: Small LisView with 3 3 Columns and binding:
<ListView x:Name="lstOrder" Margin="10,9,10,10">
<ListView.View>
<GridView>
<GridViewColumn Header= "Customer" DisplayMemberBinding="{Binding Path= customerName}"/>
<GridViewColumn Header= "Date" DisplayMemberBinding="{Binding Path= date}"/>
<GridViewColumn Header= "Price" DisplayMemberBinding="{Binding Path= priceSum}"/>
</GridView>
</ListView.View>
</ListView>
Data shall be taken from the class Order:
public class Order
{
public Customer customer;
public string date { get; set; }
public double priceSum { get; set; }
}
Date and price can be bound easily and are shown in the application, but customer name can't.
Basically I got two questions.
Thank you in advance!
Upvotes: 0
Views: 212
Reputation: 13458
You cannot bind to member fields, so turn public Customer customer;
into a property public Customer customer {get;set;}
instead. Then specify the binding path with dots {Binding Path=customer.Name}
Upvotes: 2
Reputation: 879
Please use the following:
<GridViewColumn Header= "Customer"
DisplayMemberBinding="{Binding Path= Customer.CustomerName}"/>
i.e. Customer.propertyName
in your case -> customer.customerName (it should match the property name of parent as well as the child as it is case sensitive)
Upvotes: 1