c# - Button content not displaying when using Control Template as Button Template WPF -
c# - Button content not displaying when using Control Template as Button Template WPF -
so have circular button have created in wpf so:
<button grid.column="3" width="25" height="25" content="x" margin="10,5,5,5" foreground="red" verticalalignment="center" horizontalalignment="center"> <button.template> <controltemplate> <grid> <ellipse name="ellipse" fill="{templatebinding background}"/> </grid> </controltemplate> </button.template> </button>
but button displays is:
why has reddish x not appeared in center of button? , possible alter xaml such reddish x appear. (ps. gray background because of button style in resources)
it's because there's nil in template
display content
. need utilize contentpresenter
<button grid.column="3" width="25" height="25" content="x" margin="10,5,5,5" foreground="red" verticalalignment="center" horizontalalignment="center"> <button.template> <controltemplate targettype="{x:type button}"> <grid> <ellipse name="ellipse" fill="{templatebinding background}"/> <contentpresenter horizontalalignment="center" verticalalignment="center"/> </grid> </controltemplate> </button.template> </button>
you'll need add together targettype="{x:type button}"
controltemplate
c# wpf xaml button controltemplate
Comments
Post a Comment