c# - Set Command/Action on a Button within a DataTemplate -
i have created new style tabcontrol. on tabitem have close button. now, want user able click on close button close active tab.
<style x:key="studiotabcontrol" targettype="{x:type tabcontrol}"> <style.resources> <style targettype="{x:type tabitem}"> <setter property="focusvisualstyle" value="{x:null}"/> <setter property="background" value="transparent"/> <setter property="template"> <setter.value> <controltemplate targettype="{x:type tabitem}"> <grid height="20" background="{templatebinding background}" snapstodevicepixels="true"> <grid.columndefinitions> <columndefinition width="auto"/> <columndefinition width="35"/> </grid.columndefinitions> <contentpresenter grid.column="0" margin="10,0,10,0" horizontalalignment="center" verticalalignment="center" contentsource="header" /> <button grid.column="1" width="15" height="15" horizontalalignment="center" verticalalignment="center" command= // close command operation here. dockpanel.dock="right"> ... i know can
<i:interaction.triggers> <i:eventtrigger eventname="click"> <actions:closetabitemaction tabitem="{binding relativesource={relativesource ancestortype=tabitem}}" tabcontrol="{binding relativesource={relativesource ancestortype=tabcontrol}}"/> </i:eventtrigger> </i:interaction.triggers> where close tabitem action set in template fine , via appropriate code. if wanted include second button on tab hold custom image set away template. how , how handle click of button outside of template? example of tabitem can vs2012...

thanks time.
killercam!
i've been through same menuitem on datatemplate.
what did add setter property=command inside style type button. here's code:
<datatemplate x:key="whatever"> <style targettype="menuitem"> <setter property="command" value="{binding comando}" /> <setter property="commandparameter" value="{binding texto}"/> </style> </hierarchicaldatatemplate.itemcontainerstyle> <stackpanel orientation="horizontal"> <!--<image source="{binding imagem}" />--> <accesstext text="{binding texto}" /> </stackpanel> </datatemplate> remembering {binding comando} icommnd property of viewmodel this:
private icommand _comando; public icommand comando { { return _comando; } set { _comando = value; onpropertychanged("comando"); } } at view set comando (icommand) wanted this:
viewmodel.menusubitem.add(new menuviewmodel { texto = "xxxxx", comando = whatevercommand }); hope helpful!
Comments
Post a Comment