简体   繁体   English

自定义动态网格

[英]Custom Dynamic Grid

I am trying to display items in a grid however the rows and the columns should be generated dynamically. 我正在尝试在网格中显示项目,但是行和列应该动态生成。 I actually implemented a custom control that derives from Grid control and provide additional properties such as RowCount . 我实际上实现了一个自定义控件,该控件派生自Grid控件并提供其他属性,例如RowCount

Here is a picture of the grid generated by my custom control using two dimensinal string array as datasource: 这是我的自定义控件使用两个二维字符串数组作为数据源生成的网格的图片:

在此处输入图片说明

But i think my control consumes more than needed resources because it simply destroys column and row definitions and recreates them. 但是我认为我的控件消耗的资源超过了需要的资源,因为它只会破坏列和行的定义并重新创建它们。 Is there any simpler way to implement that control? 有没有更简单的方法来实现该控件?

You don't need to create a custom control to do that for you... you can use a standard DataGrid . 您无需创建自定义控件即可为您执行此操作……您可以使用标准的DataGrid There have been a number of questions on displaying dynamic data in a DataGrid . 关于在DataGrid显示动态数据存在许多问题。 Please take a look at some of these posts: 请查看以下一些帖子:

How do I bind a WPF DataGrid to a variable number of columns? 如何将WPF DataGrid绑定到可变数量的列?
DataGridColumn Binding with Dynamically Generated Data DataGridColumn与动态生成的数据绑定
Visualizing 2D Data in a Table 可视化表格中的2D数据
Displaying multidimensional data in WPF 在WPF中显示多维数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM