In my free time I'am trying to refactor one project to full MVVM model and using WPF data binding, templating ... etc stuff. But here is the problem. I have this control which not applying data template.
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vm="clr-namespace:WPFCADCore.ViewModels.CADPrimitives;assembly=WPFCADCore"
xmlns:local="clr-namespace:WPFCADCoreControls.Views.Editors" x:Class="WPFCADCoreControls.Views.Editors.EditorBaseView"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
d:DataContext="{d:DesignData Source=EditorBaseDesignData.xaml}">
<UserControl.Resources>
<DataTemplate DataType="{x:Type vm:CADLinePrimitiveViewModel}">
<Line X1="{Binding Begin.X}" Y1="{Binding Begin.Y}"
X2="{Binding End.X}" Y2="{Binding End.Y}"
Stroke="{Binding LineColor}" StrokeThickness="{Binding LineWidth}">
</Line>
</DataTemplate>
</UserControl.Resources>
<ItemsControl ItemsSource="{Binding Entities}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Background="White"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</UserControl>
This is all I see Canvas with text string
So binding to source is working, but dataTemplate not applying automaticaly.
I tried to use DataType="vm:CADLinePrimitiveViewModel" DataType="CADLinePrimitiveViewModel" No results.
And I cant insert this template into ItemSource, because there will be different types of objects there, not only lines
ObservableCollection<ICADEntityViewModel> Entities
Where ICADEntityViewModel is interface
Any suggestions? Workarounds?