C# 如何创建一个;“命令”;正在编辑DataGridCell时的类似事件
在我的程序中,我有一个带有4个不同列的C# 如何创建一个;“命令”;正在编辑DataGridCell时的类似事件,c#,wpf,xaml,datagrid,datagridcell,C#,Wpf,Xaml,Datagrid,Datagridcell,在我的程序中,我有一个带有4个不同列的DataGrid。我希望这样,在其中一列中,当选择一个单元格进行编辑时,我能够以编程方式更改该单元格的内容。例如,在编辑时,所选单元格中的当前字符串值可能会更改为“所选”。我已经浏览了DataGridCell类,没有找到任何能够检测到单元格编辑的内容。如果xaml中的每个DataGridTextColumn都有类似“cellClick”的事件,那就太好了。如何实现这种类型的处理程序 我的数据网格的xaml: <DataGrid ItemsSource=
DataGrid
。我希望这样,在其中一列中,当选择一个单元格进行编辑时,我能够以编程方式更改该单元格的内容。例如,在编辑时,所选单元格中的当前字符串
值可能会更改为“所选”
。我已经浏览了DataGridCell
类,没有找到任何能够检测到单元格编辑的内容。如果xaml中的每个DataGridTextColumn
都有类似“cellClick”的事件,那就太好了。如何实现这种类型的处理程序
我的数据网格的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
选中时激发Selected
事件。我认为在用户编辑它之前,应该选择它
来源:要将事件转换为命令,可以使用MVVM Light中的
EventToCommand
。请参阅(图9),谢谢您的提示。问题中除了标题外没有提到命令,所以我忽略了它。但是是的,@Aybe正确地建议使用EventToCommand,如果真的打算绑定到ICommand实现。