添加一个新类DataGridHelper,用于更新datagrid
This commit is contained in:
commit
d8f1c487d5
4 files changed
+63
-9
No files matched your search
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows;
|
||||
|
||||
namespace formula_manage.UserClass
|
||||
{
|
||||
public static class DataGridHelper
|
||||
{
|
||||
public static void SetRealTimeCommit(DataGrid dataGrid, bool isRealTime)
|
||||
{
|
||||
dataGrid.SetValue(RealTimeCommitProperty, isRealTime);
|
||||
}
|
||||
|
||||
public static bool GetRealTimeCommit(DataGrid dataGrid)
|
||||
{
|
||||
return (bool)dataGrid.GetValue(RealTimeCommitProperty);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty RealTimeCommitProperty =
|
||||
DependencyProperty.RegisterAttached("RealTimeCommit", typeof(bool),
|
||||
typeof(DataGridHelper),
|
||||
new PropertyMetadata(false, RealTimeCommitCallBack));
|
||||
|
||||
private static void RealTimeCommitCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var dg = d as DataGrid;
|
||||
if (dg == null)
|
||||
return;
|
||||
EventHandler<DataGridCellEditEndingEventArgs> ceHandler = delegate (object xx, DataGridCellEditEndingEventArgs yy)
|
||||
{
|
||||
var flag = GetRealTimeCommit(dg);
|
||||
if (!flag)
|
||||
return;
|
||||
var cellContent = yy.Column.GetCellContent(yy.Row);
|
||||
if (cellContent != null && cellContent.BindingGroup != null)
|
||||
cellContent.BindingGroup.CommitEdit();
|
||||
};
|
||||
dg.CellEditEnding += ceHandler;
|
||||
RoutedEventHandler eh = null;
|
||||
eh = (xx, yy) =>
|
||||
{
|
||||
dg.Unloaded -= eh;
|
||||
dg.CellEditEnding -= ceHandler;
|
||||
};
|
||||
dg.Unloaded += eh;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user