Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editing a DataTemplate with Expression Blend for items that use a DataTemplateSelector

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?

like image 815
Greg M. Avatar asked Feb 03 '23 19:02

Greg M.


1 Answers

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?

like image 65
Paul Stovell Avatar answered Feb 06 '23 09:02

Paul Stovell