Download Silverlight

I am just starting to work with Silverlight with a very simple question. I want to show a .png image. I already did this in the page.xaml file, but I would like to do it in code (C #) so that I can add and remove images while my program is running. I saw some code in which you add an image to the Canvas children, but when I do this, the images are never displayed. Can someone provide some code and where to put it? This is what I worked with. There are no exceptions, but the image is not displayed.

page.myCanvas.Children.Add(LoadImage("Image/MrBlue"));


public Image LoadImage(string resource)
    {

        Image img = new Image();

        Uri uri = new Uri(resource, UriKind.Relative);

        ImageSource imgSrc = new System.Windows.Media.Imaging.BitmapImage(uri);

        img.SetValue(Image.SourceProperty, imgSrc);

        return img;

    }

The image is set to Resource and Do Not Copy.

+3
source share
2 answers

Silverlight , VS2008 ( , , . ...), "", , Uri , . , , , . , , , :

public void ShowPicture(Uri location)
        {
            Image pic = new Image();
            pic.Source = new BitmapImage(location);
            Grid.SetColumn(pic, 1);
            Grid.SetRow(pic, 1);
            LayoutRoot.Children.Add(pic);
        }

, using, System.Windows.Media.Imaging.

, , , http-, Uris , , , . , .

+1

, , Raumornie , , , . , , Image Silverlight MrBlue? , , .png ?

!

0

Source: https://habr.com/ru/post/1712502/


All Articles