我在 Windows 8 商店应用程序上。在这个项目中。我需要将数据发送到另一个页面。计划是,我在 MainPage.xaml 中有一个 ItemGridView,我单击新闻的图像,我需要将该新闻的 ARTICLE ID 发送到下一页,并且必须使用该 ID 创建一篇文章。
我用这个做了这个windows phone 8应用程序;
private void MainLongListSelectorSelectionChanged(object sender, SelectionChangedEventArgs e)
{
NavigationService.Navigate(
new Uri(
"/DetailsPage.xaml?selectedIndex=" +
((MyWebApi.Headline) MainLongListSelector.SelectedItem).ARTICLEID, UriKind.Relative));
}
在 win 商店应用程序中,我试试这个;
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 的值。还有其他建议吗?
谢谢你。
更新 :
这是 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)
{
}
}