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?
In the Resources tab in Expression Blend, you should be able to find the data template (either from a resource dictionary or the current screen). You can then click to edit the template. Does that help?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With