---
title: "How to Update/replace image in WFP by clicking button"  
description: "How to Update/replace image in WFP by clicking button"  
author: "Anonymous User"  
published: 2013-09-21  
updated: 2013-09-21  
canonical: https://www.mindstick.com/forum/1461/how-to-update-replace-image-in-wfp-by-clicking-button  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# How to Update/replace image in WFP by clicking button

So I have an [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) that when the [user clicks](https://answers.mindstick.com/qa/34556/if-a-user-clicks-all-the-google-ads-on-my-site-is-it-foul) on a [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) it will change it to a new item. However, whenever the user clicks on one of the button, the [window](https://www.mindstick.com/forum/161285/how-does-the-window-console-object-work-in-javascript) will go blank. How can I get this to work? Thank you.

```
private void Next_Click(object sender, RoutedEventArgs e){    if (imageNumber > 6)    {        imageNumber = 1;    }    imageNumber++;    string sUri = string.Format("@/Resources/{0}", imageSource[imageNumber]);    Uri src = new Uri(sUri, UriKind.Relative);    var bmp = new BitmapImage(src);    img.Source = bmp;           }
```

**Xaml [Code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):-**

```
<Image x:Name="img">    <Image.Source>        <BitmapImage UriSource="Resources/BlackJackTut-1.jpg" />    </Image.Source></Image>
```

## Replies

### Reply by Sumit Kesarwani

Hi Chintoo,\

In WPF application you can do same also with "pack://application:,,,/resources/imagename.png".

This way called Pack URI. This is static, but with these code you can do same an even use resource ;)

**Put image in Resources.**

```
private BitmapImage ConvertBitmapToBitmapImage(System.Drawing.Bitmap bitmap){    MemoryStream memoryStream = new MemoryStream();    bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);    BitmapImage bitmapImage = new BitmapImage();    bitmapImage.BeginInit();    bitmapImage.StreamSource = new MemoryStream(memoryStream.ToArray());    bitmapImage.EndInit();    return bitmapImage;}
```

## and then use this:

```
private void btn_Click(object sender, RoutedEventArgs e){    this.Img.Source = ConvertBitmapToBitmapImage(Properties.Resources.iamge1);}
```


---

Original Source: https://www.mindstick.com/forum/1461/how-to-update-replace-image-in-wfp-by-clicking-button

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
