开发者

Drag & Drop not work in DataGrid (WPF)

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_PreviewMouseLeft开发者_Go百科ButtonDown" 
                  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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜