c# - Handle Button command in parent Control -


i have user control main content of shown below

<itemscontrol grid.row="0" itemssource="{binding mycollection}" horizontalcontentalignment="stretch" x:name="lstexpander" >         <itemscontrol.itemspanel>             <itemspaneltemplate>                 <stackpanel orientation="horizontal" isitemshost="true" flowdirection="lefttoright" margin="0,0,0,0" />             </itemspaneltemplate>         </itemscontrol.itemspanel>         <itemscontrol.itemcontainerstyle>             <style targettype="contentpresenter">                 <setter property="margin" value="100,0,0,0"></setter>             </style>         </itemscontrol.itemcontainerstyle>         <itemscontrol.itemtemplate>             <datatemplate>                 <local:attributeexpander>/local:attributeexpander>             </datatemplate>         </itemscontrol.itemtemplate>     </itemscontrol> 

the items of control again user control i.e conditionalattributeexpander, contains button. when button click on item in items control, want command handled in parent control.

in attrubuteexpander user control have defined dependency property follow

 public icommand deletecommand     {         { return (icommand)getvalue(deletecommandproperty); }         set { setvalue(deletecommandproperty, value); }     }      // using dependencyproperty backing store deletecommandcommand.  enables animation, styling, binding, etc...     public static readonly dependencyproperty deletecommandproperty =         dependencyproperty.register("deletecommand", typeof(icommand), typeof(attrubuteexpander ), new uipropertymetadata(null)); 

i have binded deletecommand property button present in user control shown below

 <button width="20" command="{binding relativesource={relativesource findancestor, ancestortype=my:attributeexpander}, path=deletecommand, mode=oneway}"                             >                      </button> 

now in container of collection i.e viewmodel have deifned property of type icommand follow , binded command property , dependency property of user control , working fine

public icommand deletecommand      {                  {             if (deletecommand == null)             {                 deletecommand = new relaycommand(x => remove(null));             }              return deletecommand;         }                }   

and xaml follow

<datatemplate>                 <local:attributeexpander deleteconditioncommand="{binding elementname=lstexpander, path=datacontext.deletecommand}"></local:attributeexpander>             </datatemplate> 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -