简体   繁体   English

WPF访问DataGrid行元素

[英]WPF access DataGrid row element

I've a got strange situation. 我有一个奇怪的情况。 I've got a datagrid, and in one of the columns is a datepicker and checkbox. 我有一个数据网格,在其中一列中是一个日期选择器和复选框。 The checkbox if selected will disable the datepicker. 如果选中该复选框,则将禁用日期选择器。

*****************************
  *            |          *
  * DatePicker | Checkbox *
  *            |          *
*****************************

I've had a stab at this, and a poke around but can't seem to find where I'd access the datepicker row object to disable it. 我对此有过一次尝试,并四处摸索,但似乎找不到我要访问datepicker行对象以禁用它的位置。 ItemArray seems to enumerate the column values fine, but I need direct access so I can set IsEnabled ItemArray似乎可以枚举列值,但是我需要直接访问,因此可以设置IsEnabled

object selected = the_datagrid.SelectedItem; 选择的对象= the_datagrid.SelectedItem;

为什么不将DatePicker.IsEnabled绑定到CheckBox.IsChecked?

It should be possible to poke around in the visual tree to find the DatePicker next to the checkbox that the user clicked. 应该可以在可视树中四处查找,以在用户单击的复选框旁边找到DatePicker。 Another solution would be to add a bool property that the checkbox sets if checked and that controls IsEnabled of the DataPicker. 另一种解决方案是添加一个bool属性,如果选中该复选框,则会设置该属性,并控制DataPicker的IsEnabled。 The DatePicker and Checkbox should have the same DataContext since they are on the same row. 由于DatePicker和Checkbox位于同一行,因此它们应具有相同的DataContext。

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

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