wpf - Adding style to Dynamic Button -
i have adding button ui this:
button objbtn = new button(); objbtn.content = "test"; grid.children.add(objbtn);
how set style button
<controltemplate x:key="orangebuttons" targettype="{x:type button}"> <grid> <border x:name="border" background="white" borderbrush="darkgray" borderthickness="2" cornerradius="5,5,5,5" width="auto" height="auto"> </border> <contentcontrol content="{templatebinding content}" width="auto" height="auto" verticalalignment="center" horizontalalignment="center" fontsize="15"/> </grid> <controltemplate.triggers> <trigger property="ismouseover" value="true"> <setter targetname="border" property="borderbrush" value="red"/> <setter targetname="border" property="background" value="#ffffc934"/> </trigger> </controltemplate.triggers> </controltemplate>
assuming "orangebuttons" declared in resources, use findresource
method in code , apply button:
button objbtn = new button { content = "test", template = (controltemplate)grid.findresource("orangebuttons") }; grid.children.add(objbtn);
Comments
Post a Comment