wpf - How to connect MouseDoubleClick to ViewModel in an Attached Behavior? -


i trying implement attached behaviors functionality in mvvm pattern. have calendar control , handle mousedoubleclick event. doing using system.windows.interactivity , interaction.triggers. however, using blackoutdates in calendar , double-clicking on blackout date results in last valid selected date being passed mousedoubleclick method, not date clicked on.

so targeting calendardaybutton, me date clicked on, cdb doesn't have commands, need use attached behavior. i'm still not understanding how mousedoubleclick handler info viewmodel. current code:

view

<calendar horizontalalignment="left" verticalalignment="top" margin="20,48,0,0"            selecteddate="{binding reportdate, mode=twoway, updatesourcetrigger=propertychanged}"           displaydatestart="{binding reportdatestart, mode=onetime}"            displaydateend="{binding reportdateend, mode=onetime}"            local:attachedproperties.registerblackoutdates="{binding noproddates, mode=oneway}">     <calendar.calendardaybuttonstyle>         <style targettype="calendardaybutton">             <setter property="local:attachedbehaviors.isvaliddateselected"                      value="{binding validdateselected, mode=twoway}"/>         </style>     </calendar.calendardaybuttonstyle> </calendar> 


viewmodel

... private bool validdateselected;  public bool validdateselected {     { return validdateselected; }      set     {         if (validdateselected != value)         {             validdateselected = value;             raisepropertychanged("validdateselected");         }     } } ... 


attached behaviors class

using system.windows; using system.windows.controls.primitives; using system.windows.input;   namespace mdod {     public class attachedbehaviors : dependencyobject     {         public static readonly dependencyproperty isvaliddateselectedproperty =             dependencyproperty.registerattached("isvaliddateselected", typeof(bool), typeof(attachedbehaviors),              new uipropertymetadata(false, onisvaliddateselectedchanged));           public static bool getisvaliddateselected(dependencyobject obj)         {             return (bool)obj.getvalue(isvaliddateselectedproperty);         }           public static void setisvaliddateselected(dependencyobject obj, bool value)         {             obj.setvalue(isvaliddateselectedproperty, value);         }           private static void onisvaliddateselectedchanged(dependencyobject d, dependencypropertychangedeventargs e)         {             calendardaybutton cdb = d calendardaybutton;              if (cdb != null)             {                 if ((bool)e.newvalue)                 {                     cdb.mousedoubleclick += cdb_mousedoubleclick;                 }                 else                 {                     cdb.mousedoubleclick -= cdb_mousedoubleclick;                 }             }         }           private static void cdb_mousedoubleclick(object sender, mousebuttoneventargs e)         {             // how info viewmodel?         }     } } 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -