controls - How do I create a checkbox without the box (just the check) in Silverlight programmatically? -


as silverlight newbie, want create boxless readonly checkbox in silverlight4 show green checkmark. don't manage box invisible/transparent or make checkmark green, stays grey.

what tried:

        cbstatus = new checkbox();         cbstatus.isenabled = false; // read         cbstatus.visibility = system.windows.visibility.visible;         cbstatus.background =  new solidcolorbrush(colors.transparent);         cbstatus.borderbrush = new solidcolorbrush(colors.transparent);         cbstatus.foreground = new solidcolorbrush(colors.green); 

thanks ideas!

you'll need override default template. add following style app.xaml resources starting point:-

<style x:key="borderlessreadonlycheckbox" targettype="checkbox">     <setter property="background" value="transparent"/>     <setter property="foreground" value="#ff000000"/>     <setter property="horizontalcontentalignment" value="left"/>     <setter property="verticalcontentalignment" value="top"/>     <setter property="padding" value="4,1,0,0"/>     <setter property="isenabled" value="false" />     <setter property="template">         <setter.value>             <controltemplate targettype="checkbox">                 <grid>                     <grid.columndefinitions>                         <columndefinition width="16"/>                         <columndefinition width="*"/>                     </grid.columndefinitions>                     <visualstatemanager.visualstategroups>                         <visualstategroup x:name="checkstates">                             <visualstate x:name="checked">                                 <storyboard>                                     <doubleanimation storyboard.targetname="checkicon" storyboard.targetproperty="(uielement.opacity)" duration="0" to="1"/>                                 </storyboard>                             </visualstate>                             <visualstate x:name="unchecked"/>                             <visualstate x:name="indeterminate"/>                         </visualstategroup>                     </visualstatemanager.visualstategroups>                     <grid horizontalalignment="left" verticalalignment="top" width="16" height="16">                         <path x:name="checkicon" margin="1,1,0,1.5" fill="green" stretch="fill" opacity="0" width="10.5" height="10" data="m102.03442,598.79645 l105.22962,597.78918 l106.78825,600.42358 c106.78825,600.42358 108.51028,595.74304 110.21724,593.60419 c112.00967,591.35822 114.89314,591.42316 114.89314,591.42316 c114.89314,591.42316 112.67844,593.42645 111.93174,594.44464 c110.7449,596.06293 107.15683,604.13837 107.15683,604.13837 z" flowdirection="lefttoright"/>                     </grid>                     <contentpresenter                           grid.column="1"                           x:name="contentpresenter"                           content="{templatebinding content}"                           contenttemplate="{templatebinding contenttemplate}"                           horizontalalignment="{templatebinding horizontalcontentalignment}"                           verticalalignment="{templatebinding verticalcontentalignment}"                           margin="{templatebinding padding}"/>                 </grid>             </controltemplate>         </setter.value>     </setter> </style> 

now style checkbox:-

cbstatus = new checkbox(); cbstatus.style = (style)application.current.resources["borderlessreadonlycheckbox"]; 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -