Einstellung Bild-source-Programm im Metro-app das Bild nicht angezeigt

Ich habe eine Hauptseite und eine Kamera-Seite in meiner Anwendung. Die Hauptseite hat ein Bild, das nicht über seine Quelle und eine Schaltfläche. Wenn Sie auf die Schaltfläche klicken, werden Sie auf der Kamera-Seite. Auf der Kamera-Seite habe ich ein Bild aufnehmen und speichern Sie Sie in der Bildbibliothek auf das Tablett, und navigieren Sie zurück auf die Hauptseite, wo ich gerne die Quelle des Bildes, um das Bild, das ich gerade aufgenommen und gespeichert in meiner Bilder-Bibliothek. Hier ist mein entsprechender code.

MainPage.xaml

<Image  x:Name="imgResume" HorizontalAlignment="Left" Height="303" Margin="975,60,0,0" Grid.Row="1" VerticalAlignment="Top" Width="360" Stretch="UniformToFill" Loaded="img_OnLoaded"/>
<Button x:Name="btnCamera" Content="Camera" HorizontalAlignment="Left" Margin="1128,372,0,0" Grid.Row="1" VerticalAlignment="Top" RenderTransformOrigin="2.05800008773804,0.184000000357628" Height="59" Width="108" Click="Camera_Click" IsEnabled="False"/>

MainPage.xaml.cs

private void img_OnLoaded(object sender, RoutedEventArgs e)
    {
        if (txtFirstName.Text != "" && txtLastName.Text != "")
        {
            try
            {
                imgResume.Source = ImageFromRelativePath(this, Windows.Storage.KnownFolders.PicturesLibrary.Path + ((App)Application.Current).candidate.FirstName + ((App)Application.Current).candidate.FirstName + "Resume.jpg");
                imgResume.UpdateLayout();
            }
            catch
            {
                imgResume.Source = ImageFromRelativePath(this, @"Assets/logo.png");
                imgResume.UpdateLayout();
            }
            btnCamera.IsEnabled = true;
        }
    }

    public static BitmapImage ImageFromRelativePath(FrameworkElement parent, string path)
    {
        var uri = new Uri(parent.BaseUri, path);
        BitmapImage result = new BitmapImage();
        result.UriSource = uri;
        return result;
    }

Kamera.xaml.cs

private async void Capture_Click(object sender, RoutedEventArgs e)
    {
        if (mediaCaptureMgr != null)
        {
            string firstName = ((App)Application.Current).candidate.FirstName;
            string lastName = ((App)Application.Current).candidate.LastName;
            string fileName = firstName + lastName + "Resume.jpg";

            Windows.Storage.IStorageFile photo = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.ReplaceExisting);

            await mediaCaptureMgr.CapturePhotoToStorageFileAsync(Windows.Media.MediaProperties.ImageEncodingProperties.CreateJpeg(), photo);

            this.Frame.Navigate(typeof(BasicPersonalInfo));
        }
    }

Den img_OnLoaded-Methode in MainPage.xaml-Datei wird versuchen, die Bildquelle auf das Bild, das ich speichern, um die Bilder-Bibliothek, aus der Capture_click-Methode in der Kamera.xaml.cs.

Mein problem ist, dass das Bild noch nie zeigt sich auf dem Bild auf der ersten Seite! Bitte um Hilfe!!

Ich habe versucht, sowohl die zwei Antworten, aber nicht für mich arbeiten. Ich finde keine Lösung auf dieser Seite und Total für mich arbeiten. http://www.c-sharpcorner.com/UploadFile/99bb20/load-image-dynamically-from-application-uri-in-windows-store/

InformationsquelleAutor Jordan Brooker | 2012-08-06

Schreibe einen Kommentar