Topic Author
Posts: 1
Joined: 03 Apr 2018, 13:49


08 Dec 2019, 18:03

Try to work out how to do binding against a ListView column through C# and bumping into some issues...
<ListView x:Name="InventoryItemList" Grid.Row="1" Margin="4" ItemsSource="{Binding ItemsList}">
                    <GridViewColumn Header="Item" Width="96" DisplayMemberBinding="{Binding Item}" />
                    <GridViewColumn Header="Quantity" Width="64" DisplayMemberBinding="{Binding Quantity}" />
This works fine in a XAML file, loading the xaml and data binding objects to it. Great.

I'm trying to work out how to do the same thing in code, to be able to change the columns at runtime.

Inspecting the resulting objects from the XAML above gives the DisplayMemberBinding property of the GridViewColumn.

It's set to a BindingExpressionBase object.

BindingExpressionBase, or BindingExpression don't have useful constructors.

I thought I could use BindingOperations.SetBinding(target, dp) to get a BindingExpressionBase, but GridViewColumn doesn't have a DisplayMemberPathProperty to attach too.

Any ideas?


User avatar
Site Admin
Posts: 2056
Joined: 22 Dec 2011, 19:20

Re: BindingExpressionBase

11 Dec 2019, 17:14


I see that in WPF the DisplayMemberBinding property is of BindingBase type, could you please report that in our bugtracker so we can change it in a future version?

In the meantime, to create the associated expression from a Binding you can call ProvideValue:
void UpdateColumnBinding(GridViewColumn column, string path)
  Binding binding = new Binding(path);
  column.DisplayMemberBinding = (BindingExpression)binding.ProvideValue(null, null);
Hope this helps.

Who is online

Users browsing this forum: No registered users and 0 guests