Search code examples
c#windows-phone-7windows-phone-8windows-phone-8.1windows-phone

How to get image from assets folder in windows phone 8.1 and assign it to a model's property


I have a model with property as BitmapImage and I am trying to load and image from root -> Assets -> Icons folder and set it to this property . But always gives me the error "Invalid URI: The format of the URI could not be determined." We originally created this project in WP8.0 and then targeted it to 8.1

                BitmapImage bi = new BitmapImage();
                bi.UriSource = new Uri(@"../Assets/Icons/noprofilepic.png", UriKind.RelativeOrAbsolute);
                bi.CreateOptions = BitmapCreateOptions.BackgroundCreation;
                BuddyImage = bi;

Property is defined as :

    private BitmapImage _BuddyImage;
    public BitmapImage BuddyImage
    {
        get { return _BuddyImage; }
        set { _BuddyImage = value; RaisePropertyChanged("BuddyImage"); }
    }

xaml control looks like below

   <Image Source="{Binding BuddyImage}" Width="75" Height="75" Stretch="Uniform"/>

Solution

  • use ms-appx:/// for example:

      bi.UriSource = new Uri("ms-appx:///Assets/Icons/noprofilepic.png");