9
votes

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?

1
"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.
@H.B. I was trying to get to them in the Objects and Timeline panel, by the 'Edit Additional Templates' context menu. That's where it would allow me to apply an existing resource, or create a new one. Implementing the Template Selector disabled the Edit Current option.Greg M.
I suspected that it was just an issue of not finding the way to edit it rather than there being some error, in fact i had the same notion as Paul Stovell, i should have just gone ahead and suggest it instead of inquiring via that comment.H.B.

1 Answers

12
votes

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?