[英]How to create a “Command” like event when a DataGridCell is being edited
In my program I have a DataGrid
with 4 different columns. 在我的程序中,我有一个带有4个不同列的DataGrid
。 I would like to make it so that, in one of the columns, when a cell is selected for editing, I am able to change the content of that cell programmatically. 我想这样做,以便在其中一列中,当选择一个单元进行编辑时,我能够以编程方式更改该单元的内容。 For example, on edit, the current string
value in the selected cell might change to "selected"
. 例如,在编辑时,所选单元格中的当前string
值可能会更改为"selected"
。 I've looked through the DataGridCell
class here , and haven't really found anything that would detect an edit to a cell. 我在这里浏览了DataGridCell
类,还没有真正发现任何可检测到单元格编辑的内容。 It would be nice if there was like some "cellClick" event for each DataGridTextColumn
in xaml. 如果xaml中的每个DataGridTextColumn
都有一些“ cellClick”事件,那就太好了。 How do I achieve this type of handler? 如何实现这种类型的处理程序?
The xaml of my DataGrid
: 我的DataGrid
的xaml:
<DataGrid ItemsSource="{Binding SysModel.SystemCollection}" MinColumnWidth="50" ColumnHeaderStyle="{StaticResource HeaderStyle}" RowStyle="{StaticResource RowStyleWithAlternation}" CellStyle="{StaticResource CenterCellStyle}"
RowHeaderWidth="0" AlternationCount="2" GridLinesVisibility="Horizontal" SelectionUnit="Cell" CanUserAddRows="False" AutoGenerateColumns="False" Height="471" Name="dataGrid1" Width="468" Canvas.Left="40" Canvas.Top="17">
<DataGrid.Columns>
<DataGridTextColumn Header="{DynamicResource cart}" Width="Auto" IsReadOnly="True" Binding="{Binding cartNum}" />
<DataGridTextColumn Header="{DynamicResource ipAddress}" Width="100" IsReadOnly="False" Binding="{Binding ipAddress}" />
<DataGridTextColumn Header="{DynamicResource portNumber}" Width="70" IsReadOnly="False" Binding="{Binding PortNumber}" />
<!-- **This is the column that contains the cells I want to have this event for** -->
<DataGridTextColumn Header="{DynamicResource configuration}" Width="*" IsReadOnly="False" Binding="{Binding Configuration}" />
</DataGrid.Columns>
<DataGrid.Resources>
<SolidColorBrush Color="#726AA5" x:Key="{x:Static SystemColors.HighlightBrushKey}" />
</DataGrid.Resources>
</DataGrid>
DataGridCell
fires Selected
event when it is selected. Selected
DataGridCell
时将触发Selected
事件。 I presume Before it is being edited by user, it should be selected. 我想在用户对其进行编辑之前,应该先选择它。
Source: DataGridCell Events 来源: DataGridCell事件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.