This project is read-only.

Inheritance with WPF DataTemplate

Feb 28, 2013 at 10:17 AM
I use UpdateControls in my WPF application.
And I would like to ask about inherite object in WPF DataTemplate.
Suppose there is
and inherited: ObjectA : BaseObject and ObjectB : BaseObject.

I can switch views for that objects using construction which I found on this website:
In Resources:
<u:WrappedType x:Key="typeObjectA" Type={x:Type ObjectA}"/>
<u:WrappedType x:Key="typeObjectB" Type={x:Type ObjectB}"/>

<DataTemplate DataType="{StaticResource typeObjectA}">
<!-- View for ObjectA -->
<DataTemplate DataType="{StaticResource typeObjectB}">
<!-- View for ObjectB -->
Then for display one:
<ContentControl Content="{Binding}"/>
But when I tried to display in the same way same view for inherited objects (DataType for "typeBaseObject") it fails. I guess that wrapping object for UpdateControls loses information about inheritance or something like that. Is there any way to make a views upon the base type?

Feb 28, 2013 at 4:45 PM
The wrapper uses the most derived class. It does not match against the base class.

So I would recommend that you create a User Control for the view. Then you can define both Data Templates to use the same User Control.

Hope this helps!
Mar 1, 2013 at 12:32 PM
Edited Mar 1, 2013 at 12:33 PM
I think it is good solution. Thank you.