拖放删除在 DataGrid (WPF) 中不起作用

发布于 2024-12-02 06:27:10 字数 1761 浏览 0 评论 0 原文

在我的 Excel AddIn 中,我有一个 WPF 窗口。在窗口内部,有一个用户控件,其顶部有一个数据网格(称为 datagrid1)。窗口的下部有另一个用户控件,其中包含一个数据网格(称为 datagrid2)。 我想从 datagrid1 中拖动行并将其放入 datagrid2(

对于 datagrid1),

<toolkit:DataGrid 
              Style="{StaticResource DataGridStyle}"
              SelectionMode="Extended"
              ItemsSource="{Binding Relations}"
              SelectedItem="{Binding ListSelection}"
              MouseDoubleClick="dg_MouseDoubleClick"
              DragEnter="DataGrid_CheckDropTarget"
              DragLeave="DataGrid_CheckDropTarget"
              DragOver="DataGrid_CheckDropTarget"
              PreviewMouseLeftButtonDown="DG_PreviewMouseLeftButtonDown" 
                  ContextMenuOpening="dg_ContextMenuOpening"
              PreviewMouseMove="DG_MouseMove" BorderBrush="LightGray">

对于 datagrid2

<dg:DataGrid Grid.Row="1" x:Name="basketDG" Margin="5 0 5 0" Background="White"
              AutoGenerateColumns="False" 
              Style="{StaticResource DataGridStyle}"
              ItemsSource="{Binding MyItems, Mode=OneWay}" 
              SelectedItem="{Binding SelectedRelComplete}" 
              SelectionChanged="BasketDgSelectionChanged"                  
              Drop="DataGridDrop" 
              DragEnter="DataGridDragEnter" 
             >

    <Style x:Key="DataGridRowStyle"  TargetType="{x:Type dg:DataGridRow}">
        <Setter Property="AllowDrop" Value="True" />         
    </Style>
    <Style x:Key="DataGridStyle" TargetType="{x:Type dg:DataGrid}">
        <Setter Property="RowStyle" Value="{StaticResource DataGridRowStyle}" />
    </Style>

,但根本不触发事件 DragEnter(在 datagrid2 上)。

我在这里想念什么?

In my Excel AddIn, I have a WPF window. Inside the windows, there is a usercontrol which has a datagrid (call it datagrid1) in the topper part. The lower part of the window has another usercontrol which contains a datagrid (call it datagrid2) .
I want to drag rows from datagrid1 and drop them to datagrid2

for datagrid1,

<toolkit:DataGrid 
              Style="{StaticResource DataGridStyle}"
              SelectionMode="Extended"
              ItemsSource="{Binding Relations}"
              SelectedItem="{Binding ListSelection}"
              MouseDoubleClick="dg_MouseDoubleClick"
              DragEnter="DataGrid_CheckDropTarget"
              DragLeave="DataGrid_CheckDropTarget"
              DragOver="DataGrid_CheckDropTarget"
              PreviewMouseLeftButtonDown="DG_PreviewMouseLeftButtonDown" 
                  ContextMenuOpening="dg_ContextMenuOpening"
              PreviewMouseMove="DG_MouseMove" BorderBrush="LightGray">

for datagrid2

<dg:DataGrid Grid.Row="1" x:Name="basketDG" Margin="5 0 5 0" Background="White"
              AutoGenerateColumns="False" 
              Style="{StaticResource DataGridStyle}"
              ItemsSource="{Binding MyItems, Mode=OneWay}" 
              SelectedItem="{Binding SelectedRelComplete}" 
              SelectionChanged="BasketDgSelectionChanged"                  
              Drop="DataGridDrop" 
              DragEnter="DataGridDragEnter" 
             >

    <Style x:Key="DataGridRowStyle"  TargetType="{x:Type dg:DataGridRow}">
        <Setter Property="AllowDrop" Value="True" />         
    </Style>
    <Style x:Key="DataGridStyle" TargetType="{x:Type dg:DataGrid}">
        <Setter Property="RowStyle" Value="{StaticResource DataGridRowStyle}" />
    </Style>

but the event DragEnter (on datagrid2) is not triggered at all.

What do I miss here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城追梦 2024-12-09 06:27:10

经过几天的谷歌搜索和挣扎,终于我发现了一些东西

这是WPF中的一个错误,在非默认域中执行WPF应用程序时拖放将不起作用。
请参阅https://connect.microsoft.com/VisualStudio/feedback/details/422485/drag-and-drop-does-not-work-when-executing-a-wpf-application-in-a- non-default-appdomain

非常感谢 Samuel Jack 解决了这个问题并在他的博客中提出了解决方法
@ http://blog. functionfun.net/2009/10/work-around-for-wpf-bug-drag-and-drop.html

After days of googling and struggling, at last I found something

This is a bug in WPF, drag drop will not work when executing WPF application in a non-default domain.
see https://connect.microsoft.com/VisualStudio/feedback/details/422485/drag-and-drop-does-not-work-when-executing-a-wpf-application-in-a-non-default-appdomain

Thanks a lot for Samuel Jack's addressing the issue and putting a workaround in his blog
@ http://blog.functionalfun.net/2009/10/work-around-for-wpf-bug-drag-and-drop.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文