如何在Visual Studio中为WPF预览ControlTemplate设计的XAML?
在为WPF应用程序设计XAML时,Visual Studio显示了XAML代码编辑器旁边的生成预览设计。
但是,如果XAML代码在'template
'节点中,则“设计”面板不会显示预览,例如,controlTemplate
。
<ControlTemplate TargetType="{x:Type ListViewItem}">
...
<TextBlock Text="{Binding ListTitle}" /> <!-- IDE doesn't initially provide how this element will look like -->
...
</ControlTemplate>
这样的controlTemplate
节点中有很多东西,但是我必须依靠我的估计来编码XAML,而无需任何预览。然后,每次运行该应用程序,以查看这些XAML代码实际上是如何设计的。
有没有办法“预览” XAML内部ControlTemplate
节点的设计?
When designing XAML for WPF application, Visual Studio shows a generated preview design next to the XAML code editor.
However, the 'design' panel doesn't show the preview if the XAML code is in the 'Template
' node, for example, ControlTemplate
.
<ControlTemplate TargetType="{x:Type ListViewItem}">
...
<TextBlock Text="{Binding ListTitle}" /> <!-- IDE doesn't initially provide how this element will look like -->
...
</ControlTemplate>
There are a bunch of things inside such a ControlTemplate
node, yet I have to code XAML without any preview, just relying on my estimation. Then, run the application each time to see how these XAML codes actually are being designed.
Is there a way to 'preview' the design of XAML inside ControlTemplate
node?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于此问题,您可以使用XAML热装加载,因此您可以运行应用程序,更改并保存XAML代码,并同时查看更改。
要启用XAML热装,请转到工具 - &gt;选项 - &gt;调试 - &gt; XAML热重载 - &GT;在Visual Studio 2022中启用XAML热装加载。在Visual Studio 2019中,它几乎相同,我相信它是在工具中 - &gt;选项 - &gt;调试 - &gt;热重新加载。 XAML热重新加载。
For this problem, you can use XAML Hot Reload, so you run your application, change and save your xaml code and see the changes simultaneously.
To enable XAML Hot Reload, go to Tools -> Options -> Debugging -> XAML Hot Reload -> Enable XAML Hot Reload in Visual Studio 2022. In Visual Studio 2019, it's almost the same, I believe it's in Tools -> Options -> Debugging -> Hot Reload. More detail on XAML Hot Reload here.