Im my app, I have an ItemsControl element which houses user-drawn shapes. Each specific shape's ViewModel inherits from a base ViewModel. A DataTemplateSelector applies the correct DataTemplate based on the shape's ViewModel type.
in my win xaml:
<ItemsControl ItemsSource="{Binding MarkupElements}"
ItemTemplateSelector="{StaticResource MarkupTemplateSelector}"/>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Panel.ZIndex="1" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
in a resource dictionary:
<DataTemplate x:Key="MarkupLineTemplate" DataType="x:Type vm:MarkupLineViewModel">
<.../>
</DataTemplate>
<DataTemplate x:Key="MarkupCircleTemplate" DataType="x:Type vm:MarkupCircleViewModel">
<.../>
</DataTemplate>
<view:MarkupTemplateSelector
LineTemplate="{StaticResource MarkupLineTemplate}"
CircleTemplate="{StaticResource MarkupCircleTemplate}"
x:Key="MarkupTemplateSelector"/>
This works fine, but Expression Blend doesn't let me edit those templates. I can force Blend to apply a specific template, but it then adds a ItemTemplate
property to my win.xaml set to the one I chose, overriding the selector.
I'm using the MVVM Light Tookit, and tried adding a few design-time shapes of different types. Blend does show them, but they're no help with accessing the templates.
Is there a way to convince Blend that my derived ViewModels are valid for the DataContext, thus allowing me to edit the templates? Is this even the problem?
"but Expression Blend doesn't let me edit those templates"
Does it say "No you!" or how exactly is it preventing you from editing it? – H.B.Edit Current
option. – Greg M.