WPF Button with Image

In WPF, most of the controls can load an image as their content.
 
The following code sample creates two Button controls. One Button contains text and the other contains an image. When a user clicks the Button that has the image, the background and the text of the other Button change.
 
This example creates Button controls by using markup but uses code to write the click event handlers.
XAML code:
  1. <Button Name="AButton" Width="50" Height="30" Click="OnImageButtonClick">  
  2. <Image Source="data\YourImageName.jpg"></Image></Button>  
  3. <Button Name="Button2" BorderBrush="Black">Click the picture.</Button>  
You can also create an image dynamically in code and set the image as the button content.
 
Here is the button click event handler.
  1. void OnImageButtonClick(object sender, RoutedEventArgs e)  
  2. {  
  3. Button2.FontSize = 16;  
  4. Button2.Content = "This is an image";  
  5. Button2.Background = Brushes.Red;  
  6. }