Pages

Tuesday, 12 March 2013

Image Control in WPF

Image Control in WPF Window

The Image control provides rich features to display images of various formats like JPEG, PNG, ICO, BMP, GIF etc. Displaying an image is as simple as setting the Image. Source property to the appropriate image file path. No special coding is required to work with different file formats.

Example:


XAML CODE:

<Window x:Class="WpfApplication7.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="312" Width="240" Loaded="Window_Loaded">
    <Grid>
        <Image Margin="8,9,0,0" Name="image1" Stretch="Fill" Height="231" 
         VerticalAlignment="Top" HorizontalAlignment="Left" Width="197" />
    </Grid>
</Window>

.CS code to Add Image in Image Control-

private void Window_Loaded(object sender, RoutedEventArgs e)
{
            image1.Source = new BitmapImage(new Uri("2.jpeg", UriKind.Relative));
}

Designed Output-



No comments:

Post a Comment