c# - WPF DataGrid:使用 GongSolutions.WPF.DragDrop 重新排序和编辑行
问题描述
我正在使用 GongSolutions.WPF.DragDrop。我想要的是将列表加载到 DataGrid 中,能够添加行、删除行、编辑行和拖放重新排序行。然后以新顺序将列表中的每个项目读回数据库。
当我将项目源提供给 DataGrid 时,我无法拖放对行重新排序。
如果我通过 DataGrid.Items.Add 将项目添加到 DataGrid,则无法编辑行。
源代码; 主窗口.xaml
<Window
x:Class="WPFDragDropControls.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dd="urn:gong-wpf-dragdrop"
xmlns:local="clr-namespace:WPFDragDropControls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="800"
Height="450"
Loaded="Window_Loaded"
mc:Ignorable="d">
<Grid>
<DataGrid
Name="DataGrid_DD_Test"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
AutoGenerateColumns="False"
CanUserAddRows="True"
CanUserDeleteRows="True">
<DataGrid.Columns>
<DataGridTextColumn
Binding="{Binding ColumnName}"
Header="ColumnName"
IsReadOnly="False" />
<DataGridTextColumn
Binding="{Binding SystemName}"
Header="SystemName"
IsReadOnly="False" />
<DataGridTextColumn
Width="*"
Binding="{Binding Format}"
Header="Format"
IsReadOnly="False" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
主窗口.xaml.cs
using System.Collections.Generic;
using System.Windows;
namespace WPFDragDropControls{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
List<TestItems> TestCollection = new();
TestCollection.Add(new TestItems() { ColumnName = "EmployerSig", SystemName = "Form9061_1a", Format = "trim[32]" });
TestCollection.Add(new TestItems() { ColumnName = "StartDate", SystemName = "Form9061_6a", Format = "dt:yyyyMMdd" });
TestCollection.Add(new TestItems() { ColumnName = "State", SystemName = "Form9061_4ga", Format = "trim[2]" });
DataGrid_DD_Test.ItemsSource = TestCollection;
//DataGrid_DD_Test.Items.Add(new TestItems() { ColumnName = "StartDate", SystemName = "Form9061_6a", Format = "dt:yyyyMMdd" });
//DataGrid_DD_Test.Items.Add(new TestItems() { ColumnName = "State", SystemName = "Form9061_4ga", Format = "trim[2]" });
//DataGrid_DD_Test.Items.Add(new TestItems() { ColumnName = "EmployerSig", SystemName = "Form9061_1a", Format = "trim[32]" });
}
class TestItems
{
public string ColumnName { get; set; }
public string SystemName { get; set; }
public string Format { get; set; }
}
}
}
我怎样才能有我的蛋糕,也吃呢?
解决方案
推荐阅读
- c# - 更新后领域对象不可见
- php - 使按钮将数据发送到数据库(空白页在重新加载时工作?)
- php - 在没有开关的情况下拆分函数的处理和响应(寻找替代方案)
- sapui5 - 如何使简单的表单响应?
- c# - 调试期间的 CsvHelper 错误 - System.Linq.SystemCore_EnumerableDebugView
- android - 使用 Gson 反序列化,但 App 已更新(新对象结构)
- protractor - 我想在量角器黄瓜框架中并行运行 5 个 chrome 会话上的一个功能文件
- react-native - 无法在android中添加联系人
- linux - 运行 Gtlab CI 作业以使用 webdriverio 执行自动化测试时出现“加载共享库时出错:libnss3.so”
- mysql - MySQL查找每个月的员工人数