Monday, 15 February 2010

controltemplate - Silverlight Style : custom style based on custom style -



controltemplate - Silverlight Style : custom style based on custom style -

someone has done custom style buttons of application. want create custom style based on custom style. illustration want create "close button" want reuse other application. tried :

<style x:key="glassbuttonclose" targettype="button" basedon="{staticresource glassbutton}"> <setter property="horizontalalignment" value="right" /> <setter property="template"> <setter.value> <controltemplate targettype="button"> <grid> <grid.columndefinitions> <columndefinition width="auto" /> <columndefinition /> </grid.columndefinitions> <image grid.column="0" grid.row="0" source="/balisage;component/images/close.png" width="24" height="24" /> <textblock grid.column="1" verticalalignment="center" text="{binding source={staticresource loccommonstrings}, path=buttonlabelclose}" margin="0" /> </grid> </controltemplate> </setter.value> </setter> </style>

but doesn't maintain glassbutton settings. how can extend settings, keeping existing ones ?

thanks help

based on shown template , reply in comments looks need have spacific glassbutton fixed icon , text. , want utilize button without need specify content 1 time again , again.

solution: prepare own type glassstyleclosebutton.

public class glassstyleclosebutton : button { public glassstyleclosebutton() { defaultstylekey = typeof(glassstyleclosebutton); } }

and style new type (can placed in app.xaml or generic.xaml):

<style targettype="glassstyleclosebutton" basedon="{staticresource glassbutton}"> <setter property="content" value="{binding path=buttonlabelclose, source={staticresource loccommonstrings}}"/> <setter property="contenttemplate"> <setter.value> <datatemplate> <grid> <grid.columndefinitions> <columndefinition width="auto"/> <columndefinition width="*"/> </grid.columndefinitions> <image source="/balisage;component/images/close.png" width="24" height="24"/> <textblock grid.column="1" verticalalignment="center" text="{templatebinding content}"/> </grid> </datatemplate> </setter.value> </setter> </style>

and can utilize this:

<somewhereinmyapp> ... <glassstyleclosebutton/> </somewhereinmyapp>

silverlight controltemplate

No comments:

Post a Comment