如何在 Silver light 4 中单击(编辑)按钮来触发 PreparingCellForEdit 事件
我在 Silverlight 4 中有一个数据网格,有 3 列以及包含“编辑/应用”按钮的列。
行单元格最初呈现为纯文本,我需要将它们在编辑模式下更改为组合框。
单击任意行中的“编辑”按钮后。我需要将其中一行中的文本块(这是我的单元格模板)更改为组合框(这是我的单元格编辑模板)
问题是如何我是否可以通过单击每行的“编辑”按钮而不是双击该行来实现此目的。
谢谢, 维杰
I have a Data Grid in Silverlight 4 with 3 columns along with a column which contains "Edit/Apply" button.
The row cells are initially rendered as plain text and I need them to be changed to Comboboxes in the edit mode.
Once the Edit button in any of the row is clicked. I need to change the textblock( This is my Cell Template) in one of the row to the ComboBox(This is my Cell Editing template)
The question is how do i facilitate this on clicking the Edit button of each row and not by double clicking on the row.
Thanks,
Vijay
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一种方法
将文本块放在组合框(具有折叠可见性的组合框)顶部。在编辑时切换控件之间的可见性(组合 - 可见/文本块 - 折叠)并将文本块中的文本属性绑定到组合中的选定值。
第二种方式
仅放置 IsReadOnly 属性设置为 True 的组合框。编辑时将 IsReadOnly 设置为 false,保存时将其设置回 true。*
第三种方式
将数据网格设置为只读并将数据表单绑定到它。数据表单包含编辑/保存/取消按钮。
如果您需要示例,请告诉我,我会尽快写一个。
不确定这是否是您所期望的。如果没有,请忽略它。我可能误解了这个问题。
另一个答案
另一个答案是使用绑定在“编辑”按钮的 Command 属性上的 DelegateCommand,其中可以包含参数(行号)。这是如果您使用 MVVM 模式的话。在 ViewModel 中,您可以编辑选定的行。
1st way
Put the textblocks on top of the combo-boxes (comboboxes with collapsed visibility). On Edit Switch visibilities between controls (Combo - visible / TextBlock - Collapsed) and Bind the Text Property from the Textblock to the selected value from the combo.
2nd way
Put only combo-boxes with IsReadOnly Property set to True. On Edit set IsReadOnly to false and on save set it back to true.*
3rd way
Make the datagrid readonly and bind a Data Form to it. The Data Form contains edit / save / cancel buttons.
If you need an example just let me know and I'll write one as soon as possible.
Not sure if this is what you expected. If not, please just ignore it. It is possible that I missunderstood the question.
Another answer
The other answer will be to use a DelegateCommand binded on the Command property of the Edit button wich can contain a parameter (the row number). This is if you are using the MVVM pattern. And in the ViewModel you could edit the selected row.
经过一番搜索/尝试后,我能够通过单击按钮在显示和编辑模式之间切换(按钮放置在每行中)。
下面发布的是示例代码,它促进了网格中一个单元格的这种切换,它利用了两个布尔属性 ShowDefaultTemplate 和 ShowEditableTemplate ,即 VisibilityConverter 将布尔值转换为相应的可见性选项(可见或折叠)。
谢谢,
维杰
After a bit of searching / trying i was able to toggle between display and edit mode by a button click (button placed in each row).
Below posted is the sample code , which facilitates this toggle for one of the Cells in the Grid, Which makes use of Two Boolean Properties ShowDefaultTemplate and ShowEditableTemplate , The VisibilityConverter converts the boolean values to corresponding Visibility Options (Visible or Collapsed).
Thanks,
Vijay