具有许多 GridView 的 WPF 控件

发布于 2024-09-29 00:17:42 字数 408 浏览 3 评论 0原文

我有一个 WPF 用户控件,它将动态地具有任意数量的 GridView 。除了 ItemsSource 之外,每个内容本质上都是完全相同的。因此,每个都有相同的列和相同的 RowDetailsTemplate。具体来说,我实际所做的是将列设置为绑定值,然后将 RowDetailsTemplate 设置为数据模板。

本质上定义 GridView 一次并将其复制到所有其他视图的最佳方法是什么?我已尝试将 XamlWriter.Save 与资源中的 GridView 一起使用,但列和 RowDetailsTemplate 未保存。我也尝试过一种样式,但 columns 属性不可设置。

也许我在这两种方法上做错了。

I have a WPF user control that will dynamically have any number of GridViews. Each is essentially the exact same except for the ItemsSource. Therefore each have the same columns and the same RowDetailsTemplate. To be specific what I am actually doing is settings the columns to the bound values and then setting the RowDetailsTemplate to the data template.

What is the best approach to essentially define the GridView once and copy it to all the others. I have tried XamlWriter.Save with the GridView in the resources, but the columns and RowDetailsTemplate are not saved. I have also tried a style, but the columns property is not settable.

Maybe I did something wrong with the two approaches.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小红帽 2024-10-06 00:17:42

ItemsControlItemTemplate 结合使用。用于 ItemtemplateDataTemplate 应包含带有所有列定义的 GridView XAML。接下来,将 ItemsControlItemSource 绑定到您希望 GridView 用作 ItemSource 的任何数据对象的集合>。

Use an ItemsControl with ItemTemplate. The DataTemplate used for the Itemtemplate should contain the GridView XAML with all the column definitions. Next bind the ItemsControl's ItemSource to a collection of whatever data object you want the GridViews to use as ItemSource.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文