Reputation: 19396
I have a user control with a datagrid. I want to enabled drop, to drag and drop files from file explorer. I am using 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
Upvotes: 0
Views: 488
Reputation: 169420
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.
Upvotes: 1