【问题标题】:Drag & Drop not work in DataGrid (WPF)拖放在 DataGrid (WPF) 中不起作用
【发布时间】:2011-11-07 22:29:49
【问题描述】:

在我的 Excel 插件中,我有一个 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 上)根本没有触发。

我错过了什么?

【问题讨论】:

    标签: c# excel datagrid drag-and-drop


    【解决方案1】:

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

    这是 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.functionalfun.net/2009/10/work-around-for-wpf-bug-drag-and-drop.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-15
      • 2014-09-14
      • 2015-06-16
      • 2014-03-06
      • 2014-04-06
      相关资源
      最近更新 更多