1 year ago
#322445

Willy
WPF ListView: binding a nested property to GridViewColumn.DisplayMemberBinding throws exception "BindingExpression path error"
Within a ListView I have a GridViewColumn which I am trying to bind a nested property to its DisplayMemberBinding attribute:
<ListView x:Name="myListView"
ItemsSource="{Binding myObservableCollection}"
IsSynchronizedWithCurrentItem="True">
<ListView.View>
<GridView>
<GridViewColumn Header="Timestamp"
DisplayMemberBinding="{Binding Path=Timestamp}"/>
<GridViewColumn Header="Product Id"
DisplayMemberBinding="{Binding Path=Product.Id}"/>
<GridViewColumn Header="Product Name"
DisplayMemberBinding="{Binding Path=Product.Name}"/>
<GridViewColumn Header="Product Description"
DisplayMemberBinding="{Binding Path=Product.Description}"/>
</GridView>
</ListView.View>
</ListView>
In the view model I populate the observable collection. The observable collection is defined as below:
public ObservableCollection<myCustomData> myObservableCollection { get; } = new ObservableCollection<myCustomData>();
And the classes are:
internal Class myProduct
{
public string Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
public Class myCustomData
{
internal myProduct Product { set; get; } = new myProduct();
public long Timestamp { get; set; } = DateTime.UtcNow.ToFileTimeUtc();
}
In run time I get below exception, for all items bound Product.*, for example for Product.Name it says:
BindingExpression path error: 'Product' property not found on 'object' ''myCustomData' (HashCode=1858451)'. BindingExpression:Path=Product.Name; DataItem='myCustomData' (HashCode=1858451); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
wpf
listview
data-binding
wpf-controls
gridviewcolumn
0 Answers
Your Answer