wpf - Custom button content alignment -


i'm trying create custom buttons in xaml. it's going great have weird problems alignment of content.

if place custom button in "root grid", whole button clickable, , content (text of button) center-aligned.

however if place custom buttons in way:

  • border
    • stackpanel
      • mybuttons
      • mybuttons
      • etc...

then, button's - content centered, clickable on content's text. not whole button...

if set content-alignment stretch, clickable, text isn't center.

here's xaml: how can make whole button clickable in above setup?

controltemplate:

<controltemplate x:key="ollema">     <grid background="{templatebinding background}" verticalalignment="stretch">         <border name="border"              borderbrush="{templatebinding borderbrush}"             borderthickness="{templatebinding borderthickness}">             <stackpanel verticalalignment="center" horizontalalignment="center">                 <contentpresenter content="{templatebinding property=contentcontrol.content}" horizontalalignment="stretch" verticalalignment="stretch">                 </contentpresenter>             </stackpanel>         </border>     </grid> </controltemplate> 

xaml in mainwindow:

<border borderbrush="white" borderthickness="1" margin="0" width="200" background="#ff00641e" horizontalalignment="center" verticalalignment="center">     <stackpanel width="150" horizontalalignment="center" verticalalignment="center">             <togglebutton template="{staticresource ollema}" content="togglebutton" height="57" borderbrush="white" foreground="#ffe8e8e8" background="{x:null}" borderthickness="0,0,0,1"/>             <togglebutton template="{staticresource ollema}" content="togglebutton" height="57" borderbrush="white" foreground="#ffe8e8e8" background="{x:null}" borderthickness="0,0,0,1"/>             <togglebutton template="{staticresource ollema}" content="togglebutton" height="57" borderbrush="white" foreground="#ffe8e8e8" background="{x:null}" borderthickness="0,0,0,1"/>             <togglebutton template="{staticresource ollema}" content="togglebutton" height="57" borderbrush="white" foreground="#ffe8e8e8" background="{x:null}" borderthickness="0,0,0,1"/>             <togglebutton template="{staticresource ollema}" content="togglebutton" height="57" borderbrush="white" foreground="#ffe8e8e8" background="{x:null}" borderthickness="0,0,0,1"/>             <togglebutton template="{staticresource ollema}" content="togglebutton" height="57" borderbrush="{x:null}" foreground="#ffe8e8e8" background="{x:null}" borderthickness="0"/>     </stackpanel> </border> 

@demama set background in togglebutton's transparent instead of x:null

something like

<border borderbrush="white" borderthickness="1" margin="0" width="200" background="#ff00641e" horizontalalignment="center" verticalalignment="center">     <stackpanel width="150" horizontalalignment="center" verticalalignment="center">             <togglebutton template="{staticresource ollema}" content="togglebutton" height="57" borderbrush="white" foreground="#ffe8e8e8" background="transparent" borderthickness="0,0,0,1"/>             <togglebutton template="{staticresource ollema}" content="togglebutton" height="57" borderbrush="white" foreground="#ffe8e8e8" background="transparent" borderthickness="0,0,0,1"/>             <togglebutton template="{staticresource ollema}" content="togglebutton" height="57" borderbrush="white" foreground="#ffe8e8e8" background="transparent" borderthickness="0,0,0,1"/>             <togglebutton template="{staticresource ollema}" content="togglebutton" height="57" borderbrush="white" foreground="#ffe8e8e8" background="transparent" borderthickness="0,0,0,1"/>             <togglebutton template="{staticresource ollema}" content="togglebutton" height="57" borderbrush="white" foreground="#ffe8e8e8" background="transparent" borderthickness="0,0,0,1"/>             <togglebutton template="{staticresource ollema}" content="togglebutton" height="57" borderbrush="{x:null}" foreground="#ffe8e8e8" background="transparent" borderthickness="0"/>     </stackpanel> </border> 

just tried , click event invoked fine if outside contentpresenter


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -