I've declared the following types:
public interface ITest { }
public class ClassOne : ITest { }
public class ClassTwo : ITest { }
In my viewmodel I'm declaring and initializing the following collection:
public class ViewModel
{
public ObservableCollection<ITest> Coll { get; set; } = new ObservableCollection<ITest>
{
new ClassOne(),
new ClassTwo()
};
}
In my view I'm declaring the following ItemsControl
<ItemsControl ItemsSource="{Binding Coll}">
<ItemsControl.Resources>
<DataTemplate DataType="local:ClassOne">
<Rectangle Width="50" Height="50" Fill="Red" />
</DataTemplate>
<DataTemplate DataType="local:ClassTwo">
<Rectangle Width="50" Height="50" Fill="Blue" />
</DataTemplate>
</ItemsControl.Resources>
</ItemsControl>
What I expect to see is a red square followed by a blue square, instead what I see is the following:
What am I doing wrong?