如何在 WPF 中模仿这个数据网格?
在此页面上,他们显示此数据网格:
http ://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/alleditablecolumns/defaultcs.aspx
我想添加注册表类似:
当有人想要添加新注册表时,显示此 UserControl 是否很困难?我该如何开始?
At this page, they're showing this datagrid:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/alleditablecolumns/defaultcs.aspx
I'd like add registries something like that:
Is it much difficult to show this UserControl when someone wants to add a new registry? How can I start?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要设置
DataGrid
控件的样式,因为 Google 没有透露仅设置“新项目占位符”样式的方法。有关此方面的帮助,您应该查看 本教程(一共有四篇文章,都是< em>信息非常丰富
)我为这个问题编写的小演示应用程序作为测试平台,我创建了一个新的 UserControl ,它继承自 DataGrid 类,以便我可以扩展一些功能。
在此类上,我添加了两个新属性
NewItemTemplate
和IsAddingNewItem
- 当您选择要添加新项目时,IsAddingNewItem 为 true,并且 NewItemTemplate 仅在该情况下可见财产是真实的。一个非常简单的样式大纲如下:(注意:为了节省空间,这只是一个大纲;此代码实际上不会编译)
此示例中您应该关注的两个部分是 < “
”注释下的 code>ContentPresenter 及其下方几行的“切换”按钮。
这将设置
DataGrid
的样式,使其显示为 4 行:“列标题”、“新项目占位符”、“DataGrid 行”和“添加新项目按钮” - 全部由滚动条包围。然后,在使用此控件时(您将需要使用像
这样的自定义控件,并像在您的代码中那样设置NewItemTemplate
属性例如(您还应该能够在 RowDetails 模板中重用该模板来编辑各个项目,以确保整个外观和感觉相同)。
You're going to need to style the
DataGrid
control as a quick Google doesn't reveal a method to just style the "New Item Placeholder"For help on this, you should check out this tutorial (there are four articles in total, and are all very informative)
In the little demo app I wrote as a test-bed for this question, I created a new
UserControl
which inherited from theDataGrid
class so that I could extend some of the functionality.On this class I added two new properties
NewItemTemplate
andIsAddingNewItem
- IsAddingNewItem is true when you have selected that you want to add a new item, and the NewItemTemplate is visible only when that property is true.A very simple Style outline for this is below: (note: To save space, this is only an outline; This code will not actually compile)
The two parts on this example you should focus on are the
ContentPresenter
under "<!--New Item Placeholder-->
" comment and the Toggle button a few lines below it.This styles the
DataGrid
so that it is displayed in 4 rows, "Column Headers", "New Item Placeholder", "DataGrid Rows", and the "Add new item button" - All surrounded by scroll bars.Then, in using this control (you will need to use the custom control like
<controls:DataGrid ... />
and set theNewItemTemplate
property like that in your example (you should also be able to reuse that template in the RowDetails template for the editing of the individual items to ensure the same look and feel throughout).Hope this helps.