Tutorial :Sizing customized button to size of content


I've created the following very simple button style:

<ControlTemplate x:Key="SimpleButton" TargetType="{x:Type ButtonBase}">      <ContentPresenter x:Name="content" HorizontalAlignment="Center" VerticalAlignment="Center" />      <ControlTemplate.Triggers>          <Trigger Property="IsPressed" Value="True">              <Setter Property="Opacity" TargetName="content" Value="0.4"/>          </Trigger>      </ControlTemplate.Triggers>  </ControlTemplate>  

I want to use it to make small buttons that only shows a little icon with no border that is clickable.

So I have this icon, with dimensions 16 x 16 pixels, called icon.png.

<Button Template="{StaticResource SimpleButton}">      <Image Source="pack://application:,,,/Program;component/Art/icon.png" />  </Button>  

The button is placed in a horizontal StackPanel.

Now the button shows up with dimensions 34x34. How can I make sure the button is sized to the size of the image?



<Button Template="{StaticResource SimpleButton}" HorizontalAlignment="Center" VerticalAlignment="Center">          <Image Source="pack://application:,,,/Program;component/Art/icon.png" Stretch="None" />  </Button>  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »