本文介绍了UWP:DataGrid:CellEditEnding获取更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 获取更改并提交更改的正确方法是什么? < controls:DataGrid x:Name =" dataGrid" CellEditEnding = QUOT; dg_CellEditEnding" ItemsSource =" {x:Bind ViewModel.Source}"的AutoGenerateColumns = QUOT假QUOT; GridLinesVisibility = QUOT;水平"> < controls:DataGrid.Columns> private async void dg_CellEditEnding(object sender,DataGridCellEditEndingEventArgs e){} 解决方案 如果您想获取更改并提交项目,则应设置两个事件:CellEditEnding和BeginningEdit。 BeginningEdit用于获取初始设置的值。 CellEditEnding用于检索修改后的值和其他操作。 这显示在以下代码中。 在XAML中: < ;网格和GT; < controls:DataGrid x:Name =" dataGrid" CellEditEnding =" DataGrid_CellEditEnding" BeginningEdit =" DataGrid_BeginningEdit" ItemsSource =" {Binding}"的AutoGenerateColumns = QUOT假QUOT; GridLinesVisibility =" Horizontal"> < / controls:DataGrid> < / Grid> 在C#中: private void DataGrid_CellEditEnding(object sender,Microsoft.Toolkit.Uwp。 UI.Controls.DataGridCellEditEndingEventArgs e) { string newValue =(e.EditingElement as TextBox).Text; if(startValue!= newValue) { //你自己的提交,我不知道你想在哪里提交它} else { //无需修改的操作} } private string startValue = string.Empty; private void DataGrid_BeginningEdit(object sender,Microsoft.Toolkit.Uwp.UI.Controls.DataGridBeginningEditEventArgs e) { startValue =(this.dataGrid.SelectedItem as ViewModel).Name; // Change为了你自己的价值} 你可以 在 如何:在DataGrid中实现编辑和输入验证中获取有关DataGrid的更多信息控制 您可以在 WindowsCommunityToolkit-DataGrid < ○: p>< / o:p> 祝你好运, Roy What is the proper way of getting the changes and committing them?<controls:DataGridx:Name="dataGrid"CellEditEnding="dg_CellEditEnding"ItemsSource="{x:Bind ViewModel.Source}"AutoGenerateColumns="False"GridLinesVisibility="Horizontal"><controls:DataGrid.Columns>private async void dg_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e){} 解决方案 Hi, If you want to get changes and committing items, you should set two events: CellEditEnding and BeginningEdit. BeginningEdit is used to get the value of the initial setting. CellEditEnding used to retrieve the modified values and other operations. This is shown in the following code. In XAML:<Grid> <controls:DataGrid x:Name="dataGrid" CellEditEnding="DataGrid_CellEditEnding" BeginningEdit="DataGrid_BeginningEdit" ItemsSource="{Binding}" AutoGenerateColumns="False" GridLinesVisibility="Horizontal"> </controls:DataGrid> </Grid>In C#:private void DataGrid_CellEditEnding(object sender, Microsoft.Toolkit.Uwp.UI.Controls.DataGridCellEditEndingEventArgs e) { string newValue = (e.EditingElement as TextBox).Text; if (startValue != newValue) { //Your own submission, I don't know where you want to submit it } else { //Operation without modification } }private string startValue = string.Empty;private void DataGrid_BeginningEdit(object sender, Microsoft.Toolkit.Uwp.UI.Controls.DataGridBeginningEditEventArgs e) { startValue = (this.dataGrid.SelectedItem as ViewModel).Name;//Change to your own value }You can get more information about DataGrid inHow to: Implement editing and input validation in DataGrid controlAnd you can download the official example about DataGrid inWindowsCommunityToolkit-DataGrid<o:p></o:p>Best regards,Roy 这篇关于UWP:DataGrid:CellEditEnding获取更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-04 22:10