Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - WPF/MVVM - how to handle double-click on TreeViewItems in the ViewModel? -


(note - re-post first question got posted under wrong headline: here sorry!)

i have standard wpf treeview , have bound items view model classes.

i wish handle behaviour when items double-clicked (opening documents visual-studio-style).

i can event-handler fire in control housing treeview (xaml shown), how bind specific behaviour on view model classes - e.g. projectviewmodel?

preferable bound icommand-implementer, used elsewhere...

<treeview itemssource="{binding projects}" mousedoubleclick="treeview_mousedoubleclick">     <treeview.itemcontainerstyle>         <!--  style binds treeviewitem treeviewitemviewmodel.  -->         <style targettype="{x:type treeviewitem}">             <setter property="isexpanded" value="{binding isexpanded, mode=twoway}" />             <setter property="isselected" value="{binding isselected, mode=twoway}" />             <setter property="fontweight" value="normal" />             <style.triggers>                 <trigger property="isselected" value="true">                     <setter property="fontweight" value="bold" />                 </trigger>             </style.triggers>         </style>     </treeview.itemcontainerstyle>      <treeview.resources>         <hierarchicaldatatemplate datatype="{x:type implementations:projectviewmodel}" itemssource="{binding children}">             <stackpanel orientation="horizontal">                 <image width="16" height="16" margin="3,0" source="images\region.png" />                 <textblock text="{binding displayname}" />             </stackpanel>         </hierarchicaldatatemplate>          <hierarchicaldatatemplate datatype="{x:type implementations:pumpviewmodel}" itemssource="{binding children}">             <stackpanel orientation="horizontal">                 <image width="16" height="16" margin="3,0" source="images\state.png" />                 <textblock text="{binding name}" />             </stackpanel>         </hierarchicaldatatemplate>          <datatemplate datatype="{x:type implementations:pumpdesignviewmodel}">             <stackpanel orientation="horizontal">                 <image width="16" height="16" margin="3,0" source="images\city.png" />                 <textblock text="{binding name}" />             </stackpanel>         </datatemplate>     </treeview.resources> </treeview> 

updating answer bit.

i've tried alot of different approaches , still feel attached behaviors best solution. although might alot of overhead in begining isn't. keep of behaviors icommands in same place , whenever need support event matter of copy/paste , change event in propertychangedcallback.

i added optional support commandparameter.

in designer matter of selecting desired event

enter image description here

you can set either on treeview, treeviewitem or other place like.

example. set on treeview

<treeview commandbehaviors:mousedoubleclick.command="{binding yourcommand}"           commandbehaviors:mousedoubleclick.commandparameter="{binding}"           .../> 

example. set on treeviewitem

<treeview itemssource="{binding projects}">     <treeview.itemcontainerstyle>         <style targettype="{x:type treeviewitem}">             <setter property="commandbehaviors:mousedoubleclick.command"                     value="{binding yourcommand}"/>             <setter property="commandbehaviors:mousedoubleclick.commandparameter"                     value="{binding}"/>         </style>     </treeview.itemcontainerstyle> </treeview> 

and here attached behavior mousedoubleclick

public class mousedoubleclick {     public static dependencyproperty commandproperty =         dependencyproperty.registerattached("command",         typeof(icommand),         typeof(mousedoubleclick),         new uipropertymetadata(commandchanged));      public static dependencyproperty commandparameterproperty =         dependencyproperty.registerattached("commandparameter",                                             typeof(object),                                             typeof(mousedoubleclick),                                             new uipropertymetadata(null));      public static void setcommand(dependencyobject target, icommand value)     {         target.setvalue(commandproperty, value);     }      public static void setcommandparameter(dependencyobject target, object value)     {         target.setvalue(commandparameterproperty, value);     }     public static object getcommandparameter(dependencyobject target)     {         return target.getvalue(commandparameterproperty);     }      private static void commandchanged(dependencyobject target, dependencypropertychangedeventargs e)     {         control control = target control;         if (control != null)         {             if ((e.newvalue != null) && (e.oldvalue == null))             {                 control.mousedoubleclick += onmousedoubleclick;             }             else if ((e.newvalue == null) && (e.oldvalue != null))             {                 control.mousedoubleclick -= onmousedoubleclick;             }         }     }      private static void onmousedoubleclick(object sender, routedeventargs e)     {         control control = sender control;         icommand command = (icommand)control.getvalue(commandproperty);         object commandparameter = control.getvalue(commandparameterproperty);         command.execute(commandparameter);     } } 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -