我在Windows 8商店應用。在這個項目中。我需要將數據發送到另一個頁面。該計劃是,我在MainPage.xaml中有一個ItemGridView,點擊新聞的圖像,並且需要將該新聞的ARTICLE ID發送到下一頁,並且必須創建一個帶有該ID的文章。ItemGridView ItemClick在Windows應用商店應用
我用這個做了這個windows phone 8應用程序;
private void MainLongListSelectorSelectionChanged(object sender, SelectionChangedEventArgs e)
{
NavigationService.Navigate(
new Uri(
"/DetailsPage.xaml?selectedIndex=" +
((MyWebApi.Headline) MainLongListSelector.SelectedItem).ARTICLEID, UriKind.Relative));
}
在贏店的應用程序,我試試這個;
private void itemGridView_ItemClick(object sender, ItemClickEventArgs e)
{
this.Frame.Navigate(typeof (BasicPage1),
((MyWebApi.MainPageHeadline) itemGridView.SelectedItem).ARTICLEID);
}
而且我也試過這樣;
private void itemGridView_ItemClick(object sender, ItemClickEventArgs e)
{
var articleid = ((MyWebApi.MainPageHeadline) itemGridView.SelectedItem).ARTICLEID;
this.Frame.Navigate(typeof (BasicPage1), articleid);
}
但我得到的
「對象引用不設置到對象的實例。」
在該行的末尾。
我無法得到這個ID的價值。還有其他建議嗎?
謝謝。
UPDATE:
這是MainPage.xaml.cs中;
public sealed partial class MainPage : try012.Common.LayoutAwarePage
{
private string _json = "";
private MyWebApi.RootObject Headlines { get; set; }
public MainPage()
{
this.InitializeComponent();
}
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
const string urlt = "MyWebApiURL";
var hWebRequestt = (HttpWebRequest)WebRequest.Create(urlt);
hWebRequestt.Method = "GET";
hWebRequestt.BeginGetResponse(MainLongListSelectorLoadCompletedt, hWebRequestt);
}
private void MainLongListSelectorLoadCompletedt(IAsyncResult ar)
{
var request = (HttpWebRequest)ar.AsyncState;
var response = (HttpWebResponse)request.EndGetResponse(ar);
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
_json = streamReader.ReadToEnd();
Headlines = JsonConvert.DeserializeObject<MyWebApi.RootObject>(_json);
}
if (Headlines.MainPageHeadline.Count > 0)
Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() =>
{
itemGridView.ItemsSource = Headlines.MainPageHeadline.ToList();
});
}
private void itemGridView_ItemClick(object sender, ItemClickEventArgs e)
{
this.Frame.Navigate(typeof(BasicPage1),((MyWebApi.MainPageHeadline)e.ClickedItem).ARTICLEID);
}
}
而這是BasicPage1.xaml.cs;
public sealed partial class BasicPage1 : try012.Common.LayoutAwarePage
{
public BasicPage1()
{
this.InitializeComponent();
}
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
}
protected override void SaveState(Dictionary<String, Object> pageState)
{
}
}
感謝answer.I見下文在Visual Studio時,我下面調試,它得到的ID,但是,當我向前說它「值不能爲空。 參數名稱:鍵」並導航「frameState [_pageKey] = pageState;」是否是下一頁cs代碼的原因?你能幫我解答一下嗎 –
@KuthayGümüş你可以分享這兩個頁面的代碼嗎?它的這種難以判斷這樣的 – Manvik
我編輯的問題,檢查它。 –