The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

Why i can not load image from code? RRS feed

  • Question

  •  var uri = new Uri("/Mediaicon/pause.png");
                var bitmap = new BitmapImage(uri);
                play_pause.Source = bitmap;

    Monday, May 19, 2014 4:38 AM

All replies

  • Just try out this snippet...

    var image = new Image();
    image.Source = new BitmapImage(uri);
    Canvas.SetTop(image, 50);
    Canvas.SetLeft(image, 30);

    Hope it helps :) 

    Happy Coding...
    Monday, May 19, 2014 5:03 AM
  • Is this a runtime app? You need to fully qualify your Uri.

    var uri = new Uri("ms-appx:///Mediaicon/pause.png");

    Monday, May 19, 2014 5:17 AM
  • var uri = new Uri("ms-appx:///Mediaicon/pause.png",UriKind.Absolute);
    var bitmap = new BitmapImage(uri);
    play_pause.Source = bitmap;

    Please specify type of link (relative or absolute, try both of them)

    And also use the ms-appx prefix

    Monday, May 19, 2014 6:30 AM
  • Also you probably don't want to use an image for this.

    Use a glyph from Segoe UI Symbol. It will scale better. If you use an AppBarButton it is all hooked up for you:

        <AppBarButton Icon="Pause" Label="Pause" />

    Tuesday, May 20, 2014 2:25 AM