当前位置: 动力学知识库 > 问答 > 编程问答 >

load image on canvas when navigate.. which is on other canvas in other page with c# and xaml in windows app

问题描述:

I have used the following code to pick image on a canvas.Now I want add this image on another canvas which is on different page when am navigate to it.

private async void edit_click(object sender, RoutedEventArgs e)

{

Windows.Storage.Pickers.FileOpenPicker filepicker = new Windows.Storage.Pickers.FileOpenPicker();

filepicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;

filepicker.FileTypeFilter.Add(".jpg");

filepicker.FileTypeFilter.Add(".png");

filepicker.FileTypeFilter.Add(".bmp");

filepicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

Windows.Storage.StorageFile imageFile = await filepicker.PickSingleFileAsync();

if (imageFile != null)

{

Windows.UI.Xaml.Media.Imaging.BitmapImage bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();

Windows.Storage.Streams.IRandomAccessStream stream = await imageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

Image newImage = new Image();

bitmap.SetSource(stream);

newImage.Source = bitmap;

newImage.Height = 250;

newImage.Stretch = Stretch.UniformToFill;

newImage.ManipulationMode = ManipulationModes.All;

this.theCanvas.Children.Add(newImage);

}

}

private void save_click(object sender, RoutedEventArgs e)

{

this.Frame.Navigate(typeof(showdp));

}

网友答案:

You can do in many ways, one is create a static repository of images like:

public class Settings
{
 public static Image CanvasImage;
}

And set that in your code, in edit click or where you consider, and you can get and set from any part of the app using:

Settings.CanvasImage = ...
分享给朋友:
您可能感兴趣的文章:
随机阅读: