Lets say I have this:
public class Result { public bool Success { get; set; } public string Description { get; set; } }
Then I want to add another level, like this:
public class AssertionFailedResult : Result { public string Expected { get; set; } public string Actual { get; set; } }
In WPF, how would I show the simple result one way and the assertion failed result another way? I’d like to basically make a template based on type.
If you create a DataTemplate in a resource dictionary and set the DataType property, but don’t set the x:Key property, the framework will associate the DataTemplate to objects based on the object’s runtime type. For better or worse, inheritance has no effect. In other words, even if you didn’t have a template where the DataType was ‘AssertionFailedResult’, the framework would not bind objects of type ‘AssertionFailedResult’ to a template where the DataType was ‘Result’.
EDIT: Sorry, I got it backwards. DataTemplates do have a ‘polymorphic’ behavior. Styles do not. In any case, the frameworks should bind to the DataTemplate with the more specific DataType.