Reputation: 846
I have a parent class that is bind to a DataTemplate. From the parent class I have derived several child classes, which I would like to render all over the one DataTemplate, since they are very similar.
<DataTemplate DataType="{x:Type local:ParentClass}">
...
<TextBox Text="{Binding Path=TemperatureText}" ../>
...
</DataTemplate>
TemperatureText is a property which is not in the parent class, but only in some child classes. When creating child classes that do not own the property, the following error message is generated:
BindingExpression path error: 'TemperatureText' property not found on 'object...
However, I do not want to create a separate DataTemplate for all child classes because there are many. Is there an alternative?
Upvotes: 0
Views: 233
Reputation: 27338
I see two solutions.
You may create another abstract class derived from you parent class, which would have TemperatureText property, and derive all existing classes with that property from it. You will end up with two DataTempates - one for classes with TemperatureText property and second for ohter classes.
Just move TemperatureText property to the parent class and leave it empty in some derived classes
Upvotes: 2