1
votes

I'm trying to bind a subclass property to a GridViewColumn. I have a mother class M1 and 3 differents subclasses S1, S2 and S3. The GridViewColumn is filled with objects of class M1. I'd like to bind to the header of this GridViewColumn a property of S2 that isn't implemented in M1.

Could someone explain to me how to do that please ?

EDIT :

I've got this line :

<GridViewColumn DisplayMemberBinding="{Binding _s2Attr}" Header="desc" Width="100" />

The GridView ItemsSource is filled with objects of class M1 but they are all S1, S2 or S3.

1
What if type of data context will be S3 or S1, instead of S2? - Dennis
If it was the wrong type of object, you'd get an error similar to this: System.Windows.Data Error: 40 : BindingExpression path error: 'SomeProperty' property not found on 'object' 'S3' (HashCode=3806203)'. BindingExpression:Path=SomeProperty; DataItem='S3' (HashCode=3806203); target element is 'TextBlock' (Name=''); target property is 'NoTarget' (type 'Object') - Sheridan

1 Answers

0
votes

Bindings are not strongly typed, they are resolved via reflection at runtime on the concrete DataContext object. As long as your actual DataContext class is S2 then you can bind to it fine.