次の方法で共有


Updating an Image control

I had a coworker as me how to update an Image control in code. Specifically, he wanted to create a quick file browser that had a Next and Previous button to scroll through a preset list of Images.

Creating the list and iterating through directories is pretty easy, so I'll omit that (Although, if someone wants to see that code, just comment on this post, and I'll post it seperately).

Then, I just had a quick helper method that looks like this:

 public void LoadImage(Image image, string imagePath) 
{
    if (File.Exists(imagePath))
    {        image.Source = new BitmapImage(new Uri(imagePath));     } } 

The challenge that our designer ran into, is that Source requires an "ImageSource" class, and he didn't know how to create one. BitmapImage is a class that inherits from ImageSource, and simply takes a Uri in the constructor with the location of the image. The helper function accepted the Image control as an argument, just so that I could use the same method to update any number of Image controls.

And really, that's all there is to it. Of course, my version had a transparent InkCanvas on top of the Image, and I discussed how to load and save Ink in a previous post. If folks are interested, I can post more of the code for my Image/Markup Browser here.

--Dante

Comments

  • Anonymous
    June 20, 2006
    please do post some more code...

    thanks :)
  • Anonymous
    June 21, 2006
    Sure thing... I'll post the code to initialize the filelist, as well as the click handlers for the buttons to move forward and backward through said list.

    Gimme a day or two.

    --Dante