locked
Image binding to a string RRS feed

  • Question

  • Okay, so...

    I'm working on my first Windows 8 app! I know this has already been asked, but all of the results I've found haven't worked or made much sense. I want to try and bind an Image's source to a variable in my code (not XAML). If possible, I just need the simplest method possible, something like image.Source = ...

    I don't want to use an online image source, I just want to use a local image inside my project.

    If that's possible, that'd be great!


    Saturday, June 1, 2013 5:06 PM

Answers

  • Try this (instead of "ms-appx:///Assets/Logo.png", we can use variable, it is just  a string)

    See this for more details on Uri

     BitmapImage bitmapImage = new BitmapImage(new Uri("ms-appx:///Assets/Logo.png"));
                    imageToFind.Source  = bitmapImage;


    Thanks,
    Sachin
    My Samples | Personal Website


    • Edited by Sachin S Saturday, June 1, 2013 5:55 PM
    • Proposed as answer by Dave SmitsMVP Saturday, June 1, 2013 6:25 PM
    • Marked as answer by CreeperInATardis Saturday, June 1, 2013 7:26 PM
    Saturday, June 1, 2013 5:53 PM

All replies

  • Try this (instead of "ms-appx:///Assets/Logo.png", we can use variable, it is just  a string)

    See this for more details on Uri

     BitmapImage bitmapImage = new BitmapImage(new Uri("ms-appx:///Assets/Logo.png"));
                    imageToFind.Source  = bitmapImage;


    Thanks,
    Sachin
    My Samples | Personal Website


    • Edited by Sachin S Saturday, June 1, 2013 5:55 PM
    • Proposed as answer by Dave SmitsMVP Saturday, June 1, 2013 6:25 PM
    • Marked as answer by CreeperInATardis Saturday, June 1, 2013 7:26 PM
    Saturday, June 1, 2013 5:53 PM
  • Okay: Thank you SO MUCH! That is the simplest solution to this I have found. It worked very well! I've been trying to figure that out for a couple months now, and I finally just asked.

    Thanks!

    Saturday, June 1, 2013 6:02 PM