Thursday, April 7, 2016

WPF - Add an Image in a button

We can add an image in a WPF button easily.


Refer below XAML code.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<Window x:Class="ImageButton.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button HorizontalAlignment="Left" Margin="50,50,0,0" Name="button1" VerticalAlignment="Top">
            <ContentControl>
                <StackPanel Orientation="Horizontal" Width="Auto" HorizontalAlignment="Left">
                    <Image Source="/ImageButton;component/images/save.gif" Margin="0,0,5,0" Width="20" Height="20" />
                    <TextBlock Text="Image Button" VerticalAlignment="Center" Height="18" Width="Auto" />
                </StackPanel>
            </ContentControl>
        </Button>
    </Grid>
</Window>

No comments:

Post a Comment