I'm trying to design a WPF Datagrid, where the RowDetails (a textblock) will bind to the Details
string property of the grid's ItemSource elements.
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<TextBlock Text="{Binding Details}" .....
</DataTemplate>
</DataGrid.RowDetailsTemplate>
The trick is, it's possible the elements in the binded collection might not have a Details
property, in which case RowDetails should just be empty. Is there a way to have WPF binding to a property that might not even exist at runtime, without throwing an exception? (To be clear, the items in the binded collection will either all have a Details
property, or they all won't. I am not talking about a collection holding multiple object types.)
I suppose one answer is to force the users of this grid to provide objects that always have a Details property (IDetails interface or whatever), but I think it would be nice to not have to do this - I'd like the grid to be very flexible in the objects it can display.