有没有办法在 WPF 中可视化 ItemTemplate
我有一个 ItemsControl,它有一个相当复杂的 ItemTemplate,它允许用户编辑订单。不幸的是,Visual Studio 中的设计界面不显示 ItemTemplate,因此我无法获得所做更改的即时反馈。有没有办法在 Visual Studio 中可视化 ItemTemplate?这是我的控件的结构:
<ItemsControl ItemsSource="{Binding Orders, Mode=TwoWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<!-- Fairly complex form here -->
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I have an ItemsControl that has a fairly complex ItemTemplate which allows the user to edit an Order. Unfortunately the design surface in Visual Studio does not show the ItemTemplate so I don't get an instant feedback of the changes I make. Is there a way to visualize the ItemTemplate in Visual Studio? Here's the structure of my control:
<ItemsControl ItemsSource="{Binding Orders, Mode=TwoWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<!-- Fairly complex form here -->
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
过去,我只是将 DataTemplate 的内容复制到新的 WPFControl 中。有时我不得不使用一些虚拟数据才能正确查看它,但在大多数情况下它工作得很好。
In the past I've just copied the contents of the DataTemplate into a new WPFControl. Sometimes I've had to use some dummy data to view it properly, but for the most part it works fine.
如果您有复杂的 UI,最好将其重构为
UserControl
,然后您可以在 Visual Studio 中正常可视化。或者,我相信 Expression Blend(如果您有权访问它)允许您直接可视化
DataTemplate
If you have complicated UI, it might be better to refactor it out into a
UserControl
, which you can then visualise normally in Visual Studio.Alternatively, I believe that Expression Blend (if you have access to that) allows you to visualise the
DataTemplate
directly