I am currently doing this, but I am doing something wrong :):
<Style TargetType="{x:Type Button}">
<Setter Property="MinWidth" Value="90" />
<Setter Property="Width" Value="Auto" />
</Style>
I want the buttons to have some minimum width but also to have their width expand to fit the text of the button.
Remove the width and display: block and then add display: inline-block to the button. To have it remain centered you can either add text-align: center; on the body or do the same on a newly created container.
display: block and width: 100% is the correct way to go full width but you need to remove the left/right margin on the button as it pushes it outside the containing element. for more information on the box-sizing property, read the MDN docs.
To change the font size of a button, use the font-size property.
What you have to do is set the HorizontalAlignment property to Center (or Right or Left). The buttons must be getting stretched by the containing Panel.
<Style TargetType="{x:Type Button}">
<Setter Property="MinWidth" Value="90" />
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
If setting HorizontalAlignment
isn't working, check to see that you have not set a Width
- that will prevent the button from resizing. A handy trick is setting the Width
property to NaN
or ..NaN
depending upon your application's configuration (which ever doesn't throw a compilation error).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With