If you want to show a bmp, png, jpg or gif image as a button in WPF in the best quality, you can use the following XAML:

 

XAML

<Button  HorizontalAlignment="Left" Margin="312,45,0,0" Name="refreshButton" VerticalAlignment="Top" Width="60" Height="45" Cursor="Hand" Click="button1_Click">
  <Image Source="/Ada.Tip.WpfUserControls;component/Images/SmallSync.png" Stretch="None" />
</Button>

 

* The Stretch property of the Image is set to “None”, so the image is shown in it’s original dimensions. If you let WPF scale the image you might not get the best quality. I use Paint .NET to scale the image to the correct size and then show the image in it’s original dimensions in WPF.

* Ada.Tip.WpfUserControls is the name of my Visual Studio 2010 project and assembly name.

 

Add you’re image to the project and it will automatically be converted to a resource entry in you’re assembly

 

image

 

Result (Refresh button)

image

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.