导航时在画布上加载图像...在Windows应用程序中使用c#和xaml在其他页面的其他画布上

时间:2015-07-21 18:36:25

标签: c# xaml windows-applications

我使用以下代码在画布上选择图像。现在我想在导航到另一个画布时将此图像添加到另一个画面上。

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));
    }

1 个答案:

答案 0 :(得分:0)

你可以通过多种方式做到,一个是创建一个静态的图像存储库,如:

public class Settings
{
 public static Image CanvasImage;
}

并在您的代码,编辑点击或您考虑的位置设置,您可以使用以下方式从应用的任何部分进行设置:

Settings.CanvasImage = ...