c# - Styling of WPF Controls -
i have wpf win forms application. want apply styling controls in wpf. illustration current button looks
<button content="add" width="147" height="31" margin="490,10,10,10" /> i want style button, similar next (with curved borders)
how can similar style controls.
first, let's clarify requirement. qualified guess looking styling solution wpf button rounded corners, shown in calculator app here: http://webinfocentral.com/volta/manual.aspx if there @ to the lowest degree 2 solutions following:
create resourcedictionary file , reference in wpf xaml
add button style shown in next code snippet, makes rounded corners (notice property <border.cornerradius>2</border.cornerradius>) , 3 visual/gradient effects specific normal appearance, mouse on , pressed button states:
<style targettype="button" x:key="button_default"> <setter property="foreground" value="#202020"/> <setter property="fontsize" value="12" /> <setter property="template"> <setter.value> <controltemplate targettype="{x:type button}"> <border x:name="buttonbackground" borderbrush="#606060"> <contentpresenter verticalalignment="center" horizontalalignment="center"/> <border.borderthickness>0</border.borderthickness> <border.cornerradius>2</border.cornerradius> <border.background> <lineargradientbrush endpoint="0.5,1" startpoint="0.5,0"> <gradientstop color="#f5f5f5" offset="0" /> <gradientstop color="#c5c5c5" offset="0.93" /> <gradientstop color="#606060" offset="0.93" /> <gradientstop color="#404040" offset="1" /> </lineargradientbrush> </border.background> </border> <controltemplate.triggers> <trigger property="ismouseover" value="true"> <setter property="fontweight" value="bold" /> <setter targetname="buttonbackground" property="background"> <setter.value> <lineargradientbrush startpoint="0.5,0" endpoint="0.5,1" > <gradientstop color="#f5f5f5" offset="0" /> <gradientstop color="#c5c5c5" offset="0.81" /> <gradientstop color="#606060" offset="0.81" /> <gradientstop color="#404040" offset="1" /> </lineargradientbrush> </setter.value> </setter> </trigger> <trigger property="ispressed" value="true"> <setter property="fontweight" value="bold"/> <setter targetname="buttonbackground" property="background"> <setter.value> <lineargradientbrush startpoint="0.5,0" endpoint="0.5,1" > <gradientstop color="#e5e5e5" offset="0" /> <gradientstop color="#dfdfdf" offset="0.75" /> <gradientstop color="#606060" offset="0.75" /> <gradientstop color="#303030" offset="1" /> </lineargradientbrush> </setter.value> </setter> </trigger> </controltemplate.triggers> </controltemplate> </setter.value> </setter> </style> note: pertinent case, can add together properties:
<setter property="height" value="147"/> <setter property="width" value="31"/> <setter property="margin" value="490,10,10,10"/> add button reference style in xaml following:
alternatively, can add together style button in c# adding reference resourcedictionary follows (in illustration have assign/use button name):
[buttonname].style = this.resources["button_default"] style; hope help. rgds, alex
c# wpf
No comments:
Post a Comment