event handling - WPF MVVM-Light how to use the passed DragEventArgs in ViewModel -


i have read many questions , answers wpf mvvm light here, answers show 1 side (the xaml code see below) , there no viewmodel code @ all.

<i:interaction.triggers> <i:eventtrigger eventname="drop">     <cmd:eventtocommand command="{binding mode=oneway, path=dropcommand}"                         passeventargstocommand="true" /> </i:eventtrigger> 

i use in xaml grid-control , want apply drag&drop files windows explorer (wpf) application. strictly use mvvm pattern (avoid code behind completely). jfyi, in code-behind event handler of drop-event has 2 parameters: sender of type object , e of type drageventargs. need eventargs. question not how pass drageventargs xaml directly viewmodel anymore, how , use drageventargs in viewmodel (c# code). in viewmodel write command this:

public relaycommand<drageventargs> dropcommand {         {         return _dropcommand ?? (_dropcommand = new relaycommand<drageventargs>(drop);     } } private void drop() {    // here } 

i think miss in dropcommand, can use e (type of drageventargs). thank in advance.

you need like:

what missing in function definition specify argument type expecting :)

private relaycommand<drageventargs> _dropcommand; public relaycommand<drageventargs> dropcommand {   {     return _dropcommand ?? (_dropcommand = new relaycommand<drageventargs>(drop));   } } private static void drop(drageventargs e) {   // here } 

or in lamda'ish way (i lamda's):

public relaycommand<drageventargs> dragcommand { get; private set; }  public mainviewmodel() {   dragcommand = new relaycommand<drageventargs>((e) =>  /* handler code */ , (e) => true); } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -