.net - Need help converting MVVM commanding Logic to Caliburn.Micro -


i have behavior created work plain vanilla mvvm , guidance on how make work caliburn.micro.

my behavior follows:

public class dropeventbehavior : behavior<dragsource> {     protected override void onattached()     {         base.onattached();         this.associatedobject.drop += associatedobject_drop;         }      protected override void ondetaching()     {         this.associatedobject.drop -= associatedobject_drop;         base.ondetaching();     }      void associatedobject_drop(object sender, dropeventargs e)     {         if (dropeventcommand != null)             dropeventcommand.execute(e);     }      #region command      public icommand dropeventcommand     {         { return (icommand)getvalue(dropeventcommandproperty); }         set { setvalue(dropeventcommandproperty, value); }     }      // using dependencyproperty backing store dropeventcommand.  enables animation, styling, binding, etc...     public static readonly dependencyproperty dropeventcommandproperty =         dependencyproperty.register("dropeventcommand", typeof(icommand), typeof    (dropeventbehavior), new propertymetadata(null));      #endregion } 

this relay command:

public class relaycommand<t> : icommand {      #region declarations      readonly predicate<t> _canexecute;     readonly action<t> _execute;      #endregion      #region constructors      /// <summary>     /// initializes new instance of <see cref="relaycommand&lt;t&gt;"/> class , command can executed.     /// </summary>     /// <param name="execute">the execution logic.</param>     public relaycommand(action<t> execute)         : this(execute, null)     {     }      /// <summary>     /// initializes new instance of <see cref="relaycommand&lt;t&gt;"/> class.     /// </summary>     /// <param name="execute">the execution logic.</param>     /// <param name="canexecute">the execution status logic.</param>     public relaycommand(action<t> execute, predicate<t> canexecute)     {          if (execute == null)             throw new argumentnullexception("execute");         _execute = execute;         _canexecute = canexecute;     }      #endregion      #region icommand members      public event eventhandler canexecutechanged;      public virtual boolean canexecute(object parameter)     {         return _canexecute == null ? true : _canexecute((t)parameter);     }      public virtual void execute(object parameter)     {         _execute((t)parameter);     }      #endregion } 

here xaml:

   <grid.resources>       <local:mainpageviewmodel x:key="mainpageviewmodel"/>     </grid.resources>       <listbox name="listbox1" itemssource="{binding source1}">             <listbox.itemtemplate>                 <datatemplate>                     <sdk:label content="{binding name}">                         <ig:dragdropmanager.dragsource>                             <ig:dragsource isdraggable="true">                                 <i:interaction.behaviors>                                     <local:dropeventbehavior                                         dropeventcommand="{binding source={staticresource mainpageviewmodel}, path=dropcommand}"/>                                 </i:interaction.behaviors>                             </ig:dragsource>                         </ig:dragdropmanager.dragsource>                     </sdk:label>                 </datatemplate>             </listbox.itemtemplate>             <ig:dragdropmanager.droptarget>                 <ig:droptarget isdroptarget="true"/>             </ig:dragdropmanager.droptarget>    </listbox> 

this how command handled in view model:

public class dragdropeventcommands {     public icommand dropcommand     {                 {             return new relaycommand<dragdropeventargs>(                 new action<dragdropeventargs>(                     (e) =>                     {                         data dragdata = (e.dragsource label).datacontext data;                         observablecollection<data> dropsource = (e.droptarget listbox).itemssource observablecollection<data>;                          if (dragdata != null && dropsource != null)                             dropsource.add(dragdata);                     }));         }     } } 

i following:

<i:interaction.behaviors>    <local:dropeventbehavior cal:message.attach="[event dropeventcommand] = [action handledropevents($source, $eventargs)]"/> </i:interaction.behaviors> 

i not adverse using triggers. didn't work out in case because dropevent not routed event.

if can me figure out appreciate it.

thanks :-)

have found these, , help? i'm sure remember reading something, can't remember fully.

did these quick searchs see if remember, , think it.


Comments

Popular posts from this blog

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

keyboard - Smiles and long press feature in Android -

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