简体   繁体   English

我已在数据网格中启用拖放,但未触发事件处理程序

[英]I have enabled drag and drop in the datagrid but the event handler is not fired

I have a user control with a datagrid.我有一个带有数据网格的用户控件。 I want to enabled drop, to drag and drop files from file explorer.我想启用 drop,从文件资源管理器中拖放文件。 I am using MVVM.我正在使用 MVVM。

My code is this:我的代码是这样的:

<DataGrid Name="dgdFicheros" Grid.Row="1"
          AllowDrop="True"
          ItemsSource="{Binding Ficheros}"
          SelectedItem="{Binding FicherosSelectedItem}"
          dp:DataGridSelectedItemsDependencyProperty.SelectedItems="{Binding FicherosSelectedItems}"
          Style="{StaticResource DataGridDefault}">
    <DataGrid.Columns>
        <DataGridTextColumn Header="ID Fichero" Binding="{Binding IDFichero}"/>
        <DataGridTextColumn Header="Nombre" Binding="{Binding Nombre}"/>
    </DataGrid.Columns>

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Drop">
            <i:InvokeCommandAction Command="{Binding FicherosDropCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</DataGrid>


private RelayCommand<DragEventArgs> _ficherosDropCommand;
public RelayCommand<DragEventArgs> FicherosDropCommand
{
    get { return _ficherosDropCommand ?? (_ficherosDropCommand = new RelayCommand<DragEventArgs>(OnFicherosDrop, param => true)); }
}

private void OnFicherosDrop(DragEventArgs e)
{
    string dummy = "";
    dummy = dummy + " ";

    _dialogos.AbrirDialogoAceptar("Funciona.");
}

But the event handler is not fired.但是事件处理程序没有被触发。 however the mouse pointer is changed to the icon of drag action, so it seems that is enabled correctly, but it doesn't work.但是鼠标指针变成了拖动动作的图标,所以看起来是正确启用的,但它不起作用。

Thanks谢谢

You should change the type of the command from RelayCommand<DragEventArgs> to RelayCommand<object> since there is no DragEventArgs instantiated when the command is executed.您应该将命令的类型从RelayCommand<DragEventArgs>更改为RelayCommand<object> ,因为在执行命令时没有实例化DragEventArgs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM