How to put an image into a Button in WPF


Window Presentation Foundation support Rich Composition, in which you can use a control as a container. In this example i will show, how to put an image into a Button control. If you want to make highly visualize application, must use WPF, because of the strict separation of appearance and behavior you can easily change the look of a control. Now, lets take an simple example

Source Code (xaml file)

        <StackPanel Orientation="Horizontal" Width="155">
                <Image Source="home.jpg " Height="33" Width="66" Stretch="Uniform"/>
            <TextBlock Text=" Home" FontSize="20"/> 

Code Generate the following output

According to above mentioned source code, A Button control contains a stack panel so its work as a container. We already learn about stack panel in previous article. In client based application you can design more powerful application using WPF.


Post a Comment