- chrisjbampton
- Posts: 1
- Joined:
BindingExpressionBase
Try to work out how to do binding against a ListView column through C# and bumping into some issues...
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?
Thanks
Chris
Code: Select all
<ListView x:Name="InventoryItemList" Grid.Row="1" Margin="4" ItemsSource="{Binding ItemsList}">
<ListView.View>
<GridView>
<GridViewColumn Header="Item" Width="96" DisplayMemberBinding="{Binding Item}" />
<GridViewColumn Header="Quantity" Width="64" DisplayMemberBinding="{Binding Quantity}" />
</GridView>
</ListView.View>
</ListView>
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?
Thanks
Chris
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: BindingExpressionBase
Hi,
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:
Hope this helps.
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:
Code: Select all
void UpdateColumnBinding(GridViewColumn column, string path)
{
Binding binding = new Binding(path);
column.DisplayMemberBinding = (BindingExpression)binding.ProvideValue(null, null);
}
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: BindingExpressionBase
In Noesis 3 the Binding expects an object implementing the IProvideValueTarget interface. Something like this:
Then you can pass an instance of this object setting the corresponding TargetObject and TargetProperty (null in this case):
Code: Select all
public struct ProvideValueTarget : IServiceProvider, IProvideValueTarget
{
public object TargetObject { get; set; }
public object TargetProperty { get; set; }
object IServiceProvider.GetService(Type serviceType)
{
return serviceType == typeof(IProvideValueTarget) ? (object)this : null;
}
}
Code: Select all
void UpdateColumnBinding(GridViewColumn column, string path)
{
Binding binding = new Binding(path);
column.DisplayMemberBinding = (BindingExpression)binding.ProvideValue(new ProvideValueTarget());
}
- colin14321
- Posts: 12
- Joined:
Re: BindingExpressionBase
Hi there,
I just want clarification, is this going to be left as a BindingExpressionBase in the future, or will this be changed back to BindingBase to match WPF?
Thank you.
I just want clarification, is this going to be left as a BindingExpressionBase in the future, or will this be changed back to BindingBase to match WPF?
Thank you.
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: BindingExpressionBase
Hi colin, we had a pending issue to solve this (#1337). I added it for our next major version roadmap to avoid breaking current code in 3.1.X versions.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 19 guests