Adding Images to Resource in WPF

Introduction

To display image in your application you need to add your images to resource with you folder path where the images exist.

Syntax for adding images to resource

<BitmapImage x:Key="KeyName" UriSource="ImagePath"/>

Code

<Window.Resources>

  <ResourceDictionary>

    <BitmapImage x:Key="Connected" UriSource="/Image/connected.png"/>

    <BitmapImage x:Key="Disconnected" UriSource="/Image/disconnected.png"/>

    <BitmapImage x:Key="Login" UriSource="/Image/login.png"/>

    <BitmapImage x:Key="Logout" UriSource="/Image/logout-b.png"/>

  </ResourceDictionary>

</Window.Resources>

Above code is for adding images to resource.

Code for use resource in image control

<Image Stretch="Uniform" DockPanel.Dock="Top" Source="Image/Fill.png" ></Image>