我剛剛開始爲Windows 8開發,並且在傳遞頁面之間的導航參數時遇到了一些困難。Windows 8導航,傳遞一個URI作爲參數
我想要做的是:我有兩頁(page1和page2)在page1中,有一個按鈕菜單。當我點擊這個按鈕時,點擊事件應該作爲參數傳遞一個可能的URI或路徑,它將在page2中設置圖像的來源。
這是第1頁中的代碼:
private void Button_Click_2(object sender, RoutedEventArgs e)
{
//this.Frame.Navigate(typeof(SplitPage), "ms-appx:/Imgs/1.png");
this.Frame.Navigate(typeof(SplitPage), new Uri("ms-appx:/Imgs/1.png", UriKind.RelativeOrAbsolute));
}
和第2頁,用於接收烏里:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var imgSource = e.Parameter as ImageSource;
this.imgParaPintar.Source = imgSource;
}
我注意到,imgSource
正在接收什麼,它保持爲空。
因此,任何線索我做錯了什麼或我失蹤?
您正在傳遞'Uri',然後將其轉換爲'ImageSource'。 'ImageSource'不是'Uri',你爲什麼認爲這會起作用? – svick 2012-03-28 12:28:27
那個'Image'類是否有'UriSource'參數? – 2012-03-28 13:14:20
@svick,我給出了我正在處理的兩個選項,就像您在註釋行中看到的一樣。兩者都不起作用。 – Boga 2012-03-28 13:33:22