我目前正在做一個應用程序,我需要將選定寵物的詳細信息傳遞到新的「配置文件」頁面。就目前而言,我已經獲得了所有需要傳遞的數據(姓名,年齡等),以便進入我的新配置文件頁面,但是現在我遇到了問題,因爲我嘗試通過所選寵物的照片來通過它崩潰應用程序。在C中傳遞圖像#
首先這是我宣佈我的泛型列表,在App.xaml中
private void Application_Launching(object sender, LaunchingEventArgs e)
{
myshop.Add(new Shop{Name = "Johnny", Age= 2, Breed="Husky", Type= "Dog", Stock = 1, Price = 125, Photo = "/Assignment 1;component/Images/Husky.jpg"});
myshop.Add(new Shop{Name = "Billy", Age= 1, Breed="Shiba Inu", Type= "Dog", Stock = 1, Price = 250, Photo = "/Assignment 1;component/Images/Shiba Inu.jpg"});
myshop.Add(new Shop{Name = "Sammy", Age = 8, Breed="Siamese", Type="Cat", Stock = 1, Price = 15, Photo = "/Assignment 1;component/Images/Siamese Cat.jpg"});
myshop.Add(new Shop{Name = "Molly", Age = 6, Breed="Norwegian", Type="Cat", Stock = 1, Price = 30, Photo = "/Assignment 1;component/Images/NorwegianForestCat.jpeg"});
myshop.Add(new Shop{Name = "Nemo", Age = 3, Breed="Clown Fish", Type="Fish", Stock = 1, Price = 10, Photo = "/Assignment 1;component/Images/clown Fish.jpg"});
myshop.Add(new Shop{Name = "Dory", Age = 1, Breed="Palette SurgeonFish", Type="Fish", Price = 75, Stock = 1, Photo = "/Assignment 1;component/Images/Palette Surgeonfish.jpg"});
myshop.Add(new Shop{Name = "Keith", Age = 4, Breed="Bearded Dragon", Type="Lizard", Stock = 1, Price = 750, Photo = "/Assignment 1;component/Images/Bearded Dragon.jpg"});
myshop.Add(new Shop {Name = "Oisin", Age = 12, Breed = "Gecko", Type = "Lizard", Stock = 1, Price = 90, Photo = "/Assignment 1;component/Images/Gecko.jpg" });
}
這裏就是我試圖通過細節
private void list_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
Shop selectedPet = list.SelectedItem as Shop;
String photo = selectedPet.Photo;
String breed = selectedPet.Breed;
String name = selectedPet.Name;
int age = selectedPet.Age;
int price = selectedPet.Price;
NavigationService.Navigate(new Uri("/Profile.xaml?name=" + name + "&breed=" + breed + "&age=" + age + "&price=" + "€" + price + "&photo=" + photo, UriKind.Relative));
}
打發那部分代碼工作得很好,並正確地傳遞了細節,但現在我已經添加到照片中通過它正在崩潰。這就是我所說的傳送數據到新的頁面
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
string photo;
string name;
string age;
string breed;
string price;
if (NavigationContext.QueryString.TryGetValue("photo", out photo))
{
imgPhotoHolder.Source = null;
BitmapImage myImage = new BitmapImage
(new Uri("/Assignment 1;component/Images/" + photo, UriKind.Relative));
imgPhotoHolder.Source = myImage;
}
if (NavigationContext.QueryString.TryGetValue("name", out name))
{
nameTxtBlock.Text = name;
}
if(NavigationContext.QueryString.TryGetValue("age", out age))
{
ageTxtBlock.Text = age;
}
if(NavigationContext.QueryString.TryGetValue("breed", out breed))
{
breedTxtBlock.Text = breed;
}
if (NavigationContext.QueryString.TryGetValue("price", out price))
{
priceTxtBlock.Text = price;
}
}
這個問題似乎從這個代碼片段
+ "&photo=" + photo
我知道這是之所以產生的代碼,因爲當你註釋掉只是這一點的代碼,它會工作得很好,並通過細節,但當取消註釋時,它會導致應用程序崩潰,當你選擇一個商店的項目(見下圖)
所以我只是想知道如果有人有一個想法如何解決這一點的代碼或如何正確得到我法師傳遞到下一頁。 由於提前, 傑森
的地步,你選擇一個圖像:
當你點擊的圖像,並在細節應顯示:
和錯誤是...? –
事實上,當我試圖傳遞一個圖像到個人資料頁面,它只是崩潰的應用程序 – JasonL95
...它崩潰的應用程序與異常? *什麼是錯誤?* –