使用 Expression Blend 编辑使用 DataTemplateSelector 的项目的 DataTemplate
在我的应用程序中,我有一个 ItemsControl 元素,其中包含用户绘制的形状。每个特定形状的 ViewModel 都继承自基本 ViewModel。 DataTemplateSelector 根据形状的 ViewModel 类型应用正确的 DataTemplate。
在我的 win xaml 中:
<ItemsControl ItemsSource="{Binding MarkupElements}"
ItemTemplateSelector="{StaticResource MarkupTemplateSelector}"/>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Panel.ZIndex="1" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
在资源字典中:
<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"/>
这工作正常,但 Expression Blend 不允许我编辑这些模板。我可以强制 Blend 应用特定模板,但它随后会向我的 win.xaml 添加一个 ItemTemplate
属性,设置为我选择的模板,从而覆盖选择器。
我正在使用 MVVM Light Tookit,并尝试添加一些不同类型的设计时形状。 Blend 确实显示了它们,但它们对访问模板没有帮助。
有没有办法让 Blend 相信我派生的 ViewModel 对 DataContext 有效,从而允许我编辑模板?这还是问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Expression Blend 的资源选项卡中,您应该能够找到数据模板(从资源字典或当前屏幕)。然后您可以单击以编辑模板。这有帮助吗?
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?