wpf - Giving a button in a textbox functionality, without using a custom control but overiding the textbox template -
i implemented button textbox overriding template code below:
<style x:key="{x:type textbox}" targettype="{x:type textboxbase}"> <setter property="template"> <setter.value> <controltemplate targettype="{x:type textboxbase}"> <border name="border" cornerradius="2" padding="2" background="{staticresource windowbackgroundbrush}" borderbrush="{staticresource solidborderbrush}" borderthickness="1"> <grid x:name="layoutgrid"> <grid.columndefinitions> <columndefinition width="*" /> <columndefinition width="auto" /> <columndefinition width="auto" /> </grid.columndefinitions> <scrollviewer x:name="part_contenthost" grid.column="0" /> <button x:name="xbutton" grid.column="2" width="25" height="25" content="x" visibility="visible" borderbrush="transparent" command="{binding buttonclick}" /> </grid> </border> </controltemplate> </setter.value> </setter> </style>
the button should delete content in textbox when hit. use command "command="{binding buttonclick}""
can binding done without creating custom control , library ? or how can binding or functionality done ?
i using mvvm pattern there way example use viewmodel , create property bind ?
for bindings in style use attachedcommandbehaviors "acb"
http://marlongrech.wordpress.com/2008/12/13/attachedcommandbehavior-v2-aka-acb/
i use detecting clicks on items in style want detect clicks on. haven't used buttons think should work well.
i binding style's ancestor who's type user control may need changed application.
you'll need add xmlns:acb namespace in xaml see link details.
<controltemplate targettype="{x:type listviewitem}"> <stackpanel x:name="iconborder" acb:commandbehavior.event="previewmouseup" acb:commandbehavior.command="{binding path=datacontext.selectedlistitemsingleclickcommand, relativesource={relativesource mode=findancestor, ancestortype={x:type usercontrol}}}" acb:commandbehavior.commandparameter="{binding}"> <dockpanel lastchildfill="false" horizontalalignment="left" width="{binding width, relativesource={relativesource mode=findancestor, ancestortype={x:type listviewitem}}}"> <textblock text="{binding title}" dockpanel.dock="left" x:name="listitemtext" /> <image x:name="actionicon" source="{binding path=datacontext.selectedlistactionicon, relativesource={relativesource mode=findancestor, ancestortype={x:type usercontrol}}}" dockpanel.dock="right" acb:commandbehavior.event="previewmouseup" acb:commandbehavior.command="{binding path=datacontext.selectedlistactioniconclickcommand, relativesource={relativesource mode=findancestor, ancestortype={x:type usercontrol}}}" acb:commandbehavior.commandparameter="{binding}"> </image> </dockpanel> <contentpresenter dockpanel.dock="left" /> </stackpanel> </controltemplate>
Comments
Post a Comment