0

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')

Willy
  • 9,848
  • 22
  • 141
  • 284
  • 1
    it should be `public` instead of `internal` – ASh Mar 22 '22 at 17:30
  • @ASh Ok, I see. Finally I have created those properties as public ones within myCustomData that retrieve their values from the internal class myProduct so I can bind them without problems. In my case it is not viable to change internal to public. Thx. – Willy Mar 22 '22 at 20:27

0 Answers0