Я объявляю изображение в XAML, но хочу установить изображение, показанное на C #, как оно находится в изолированном хранилище

Я могу объявить мое изображение вот так в моем xaml

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanelx" Grid.Row="1" Margin="0,0,0,0">
    <Image x:Name="MyImage" Height="150" HorizontalAlignment="Left" Margin="141,190,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="200" />
</Grid>

Я могу загрузить свое изображение из изолированного хранилища через.xaml.cs вот так

void loadImage()
{
    // The image will be read from isolated storage into the following byte array

    byte[] data;

    // Read the entire image in one go into a byte array

    using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream isfs = isf.OpenFile("0.jpg", FileMode.Open, FileAccess.Read))
        {
            data = new byte[isfs.Length];
            isfs.Read(data, 0, data.Length);
            isfs.Close();
        }
    }

    MemoryStream ms = new MemoryStream(data);
    BitmapImage bi = new BitmapImage();
    bi.SetSource(ms);

    Image image = new Image();
    image.Height = bi.PixelHeight;
    image.Width = bi.PixelWidth;

    image.Source = bi;    
}

Когда я набираю MyImage. Я не могу найти способ установить его на изображение, которое я только что создал. Может кто-нибудь из вас, ребята, посоветуйте, пожалуйста?

0
задан Michał Powaga 26 April 2012 в 12:54
поделиться