Design View of a DataTemplate in a ResourceDictionary in Visual Studio

冷暖自知 提交于 2019-11-29 17:02:50

问题


Is there a way to preview GUI in a DataTemplate? e.g. if I have a Resource Dictionary, containing a DataTemplate, and the Data template contains GUI code, like

<DataTemplate x:Key="MyTemplate">
    <StackPanel>
        <TextBox Text="AAA"/>
    </StackPanel>
</DataTemplate>

Can I view just the stackpanel? (like previewing a UserControl in design view). If not possible with original VS, is there a plugin for that?


回答1:


Visual Studio doesn't support doing this, but Expression Blend does, if you can get access to it. Here's some instructions on several ways to edit template resources:

http://msdn.microsoft.com/en-us/library/cc294908(v=expression.40).aspx

In particular, if you'd like to edit a DataTemplate located in a ResourceDictionary you would:

  • Load the project in Blend
  • Locate the .xaml file containing the ResourceDictionary in the Resources panel (docked right by default)
  • Locate the DataTemplate in the list of resources (by Key)
  • Click Edit Resource

I know this an old question but I hope this helps!




回答2:


If you reference your template down in the body of your control, such as ItemTemplate="{StaticResource MyTemplate}", you can place your cursor on the name of the template and press F12 to have Visual Studio render the template in the XAML designer.

For some reason, this only works once. You have to close and reopen the form to see another template rendered. Surely there's some way to avoid this but I haven't been able to figure it out.



来源:https://stackoverflow.com/questions/15922523/design-view-of-a-datatemplate-in-a-resourcedictionary-in-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!