|
@@ -169,14 +169,16 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
DataGrid.DragOver += DataGrid_DragOver;
|
|
|
DataGrid.RowDragDropTemplate = TemplateGenerator.CreateDataTemplate(() =>
|
|
|
{
|
|
|
- var border = new Border();
|
|
|
- border.Width = 100;
|
|
|
- border.Height = 100;
|
|
|
- border.BorderBrush = new SolidColorBrush(Colors.Firebrick);
|
|
|
- border.Background = new SolidColorBrush(Colors.Red);
|
|
|
- border.CornerRadius = new CornerRadius(5);
|
|
|
- return border;
|
|
|
+ // var border = new Border();
|
|
|
+ // border.Width = 100;
|
|
|
+ // border.Height = 100;
|
|
|
+ // border.BorderBrush = new SolidColorBrush(Colors.Firebrick);
|
|
|
+ // border.Background = new SolidColorBrush(Colors.Red);
|
|
|
+ // border.CornerRadius = new CornerRadius(5);
|
|
|
+ // return border;
|
|
|
+ return null;
|
|
|
});
|
|
|
+ DataGrid.RowDropIndicatorMode = DropIndicatorMode.Line;
|
|
|
|
|
|
DataGrid.CurrentCellBorderThickness = new Thickness(0);
|
|
|
DataGrid.AllowFiltering = false;
|
|
@@ -550,15 +552,16 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
DataGrid.AllowEditing = allowEditing;
|
|
|
reloadColumns = true;
|
|
|
}
|
|
|
- DataGrid.AllowFiltering = Parent.Options.FilterRows;
|
|
|
- DataGrid.FilterRowPosition = Parent.Options.FilterRows ? FilterRowPosition.FixedTop : FilterRowPosition.None;
|
|
|
+ DataGrid.AllowFiltering = Parent.Options.FilterRows && Parent.CanFilter();
|
|
|
+ DataGrid.FilterRowPosition = Parent.Options.FilterRows && Parent.CanFilter() ? FilterRowPosition.FixedTop : FilterRowPosition.None;
|
|
|
|
|
|
- if (Parent.Options.DragSource)
|
|
|
+ if (Parent.Options.DragSource || Parent.Options.DragRows)
|
|
|
{
|
|
|
if (!DataGrid.AllowDraggingRows)
|
|
|
{
|
|
|
DataGrid.AllowDraggingRows = true;
|
|
|
DataGrid.RowDragDropController.DragStart += RowDragDropController_DragStart;
|
|
|
+ DataGrid.RowDragDropController.DragOver += RowDragDropController_DragOver;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -567,16 +570,34 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
{
|
|
|
DataGrid.AllowDraggingRows = false;
|
|
|
DataGrid.RowDragDropController.DragStart -= RowDragDropController_DragStart;
|
|
|
+ DataGrid.RowDragDropController.DragOver -= RowDragDropController_DragOver;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Parent.Options.DragTarget || Parent.Options.DragRows)
|
|
|
+ {
|
|
|
+ if (!DataGrid.AllowDrop)
|
|
|
+ {
|
|
|
+ DataGrid.AllowDrop = true;
|
|
|
+ DataGrid.RowDragDropController.Drop += RowDragDropController_Drop;
|
|
|
+ DataGrid.RowDragDropController.Dropped += RowDragDropController_Dropped;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (DataGrid.AllowDrop)
|
|
|
+ {
|
|
|
+ DataGrid.AllowDrop = false;
|
|
|
+ DataGrid.RowDragDropController.Drop -= RowDragDropController_Drop;
|
|
|
+ DataGrid.RowDragDropController.Dropped -= RowDragDropController_Dropped;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- DataGrid.AllowDrop = Parent.Options.DragTarget;
|
|
|
|
|
|
DataGrid.SelectionMode = Parent.Options.MultiSelect ? GridSelectionMode.Extended : GridSelectionMode.Single;
|
|
|
|
|
|
return reloadColumns && DataGrid.Columns.Count > 0;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void DataGrid_FilterChanging(object? sender, GridFilterEventArgs e)
|
|
|
{
|
|
|
|
|
@@ -1828,11 +1849,19 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
|
|
|
private void DataGrid_DragOver(object sender, DragEventArgs e)
|
|
|
{
|
|
|
+ if (!Parent.Options.DragTarget)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
Parent.DragOver(sender, e);
|
|
|
}
|
|
|
|
|
|
private void DataGrid_Drop(object sender, DragEventArgs e)
|
|
|
{
|
|
|
+ if (!Parent.Options.DragTarget)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
Parent.Drop(sender, e);
|
|
|
}
|
|
|
|
|
@@ -1846,5 +1875,50 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
Parent.DragStart(sender, rows);
|
|
|
}
|
|
|
|
|
|
+ private void RowDragDropController_Drop(object? sender, GridRowDropEventArgs e)
|
|
|
+ {
|
|
|
+ if (!Parent.Options.DragRows)
|
|
|
+ {
|
|
|
+ e.Handled = true;
|
|
|
+ }
|
|
|
+ e.Handled = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void RowDragDropController_Dropped(object? sender, GridRowDroppedEventArgs e)
|
|
|
+ {
|
|
|
+ if (!Parent.Options.DragRows)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ if(e.DropPosition != DropPosition.None)
|
|
|
+ {
|
|
|
+ var records = (e.Data.GetData("Records") as ObservableCollection<object>)!;
|
|
|
+ var targetIdx = (int)e.TargetRecord;
|
|
|
+
|
|
|
+ var rows = records.Select(x =>
|
|
|
+ {
|
|
|
+ if (x is DataRowView dataRow)
|
|
|
+ {
|
|
|
+ var row = dataRow.Row.Table.Rows.IndexOf(dataRow.Row);
|
|
|
+ return Parent.Data.Rows[row];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }).NotNull().OrderBy(x => x.Index).ToArray();
|
|
|
+
|
|
|
+ Parent.MoveRows(rows, e.DropPosition == DropPosition.DropBelow ? targetIdx + 1 : targetIdx);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void RowDragDropController_DragOver(object? sender, GridRowDragOverEventArgs e)
|
|
|
+ {
|
|
|
+ if (!Parent.Options.DragRows)
|
|
|
+ {
|
|
|
+ e.Handled = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
}
|