tags:

views:

307

answers:

2

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.

A: 

If you just set MinWidth of button and if your text width is bigger than min width it will automatically expand, but in reverse case button will be same with your min width,

<Style TargetType="{x:Type Button}"> <Setter Property="MinWidth" Value="90" /> </Style>

that is enough to archive to required result

Firoz
hmm why didn't it work then... Could a containing element's style be messing with the buttons? They are still stretching to fill...
Alex Baranosky
Ahhh.. I had to add: <Setter Property="HorizontalAlignment" Value="Center" /> The stack panels were setting them to stretch, I believe.
Alex Baranosky
A: 

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>
Alex Baranosky