使用来自web service的json数据在windows phone应用程序中创建一个主从视图

本文关键字:创建 视图 一个 应用程序 phone web service windows 数据 json | 更新日期: 2023-09-27 18:11:51

我想选择一个列表框项,并在下一页的文本块中显示其详细信息。这是我的代码。请帮助我或给我一些链接,我可以参考…提前谢谢。

这是我的主页xaml。

<ListBox x:Name="lstUniversity" Height="582" SelectionMode="Single" FontSize="30"     VerticalAlignment="Bottom">
          <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="1">
                    <Button Name="btn" Content="{Binding NAME}" Click="click" BorderThickness="1"  HorizontalContentAlignment="Left"
                        Height="75" Width="460" FontSize="24" 
                        HorizontalAlignment="Stretch"
                        CommandParameter="{Binding}" Foreground="White"/>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

我的主页c#代码

public class University
{
    public string UID { get; set; }
    public string NAME { get; set; }
    public string RANK { get; set; }
    public string FEES { get; set; }
    public string APPLIEDFEES { get; set; }
    public string CITY { get; set; }
    public string STATE { get; set; }
}
protected override void OnNavigatedTo(NavigationEventArgs args)
{
   try
   {
      WebClient webClient = new WebClient();
      Uri uri = new Uri("http://www.mastertionary.com/ios/connect1.php");
      webClient.DownloadStringCompleted += new         DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
  webClient.DownloadStringAsync(uri);
   }
   catch (Exception ex)
   {
      MessageBox.Show(ex.Message);
   }
}     
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    var rootObject = JsonConvert.DeserializeObject<List<University>>(e.Result);
        lstUniversity.ItemsSource = rootObject;
}
public void click(object sender, RoutedEventArgs e)
{   
  NavigationService.Navigate(new Uri("/details.xaml", UriKind.Relative));
}

My details page xaml is

<ListBox x:Name="unidetails" Height="582" SelectionMode="Single" FontSize="30" VerticalAlignment="Bottom">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="1">
                    <StackPanel><TextBlock Text="{Binding NAME}" Height="100" Width="300"/>
                    <TextBlock Text="{Binding RANK}" Height="100" Width="300"/>
                    <TextBlock Text="{Binding FEES}" Height="100" Width="300"/>
                    <TextBlock Text="{Binding APPLIEDFEES}" Height="100" Width="300"/>
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

请帮助我如何根据从母版页面中选择的项目显示排名,费用等详细信息?

使用来自web service的json数据在windows phone应用程序中创建一个主从视图

  1. 您可以将对象存储在PhoneApplicationState中,并在下一页检索它。

      if (PhoneApplicationService.Current.State.ContainsKey("ApplicationDataObject"))
      {
        // If it exists, assign the data to the application member variable.
        ApplicationDataStatus = "data from preserved state.";
        ApplicationDataObject = PhoneApplicationService.Current.State["ApplicationDataObject"] as University;
      }
    

    参考:http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff967547 (v = vs.105) . aspx

  2. 或者,使用可以从两个页面引用的静态对象。

  3. 如果参数不多,则发送查询参数中的数据如下:例如,如果您已经将列表框与List绑定,那么您可以在列表框Tap事件中访问选中的项目,如:

    University univObj = listbox.SelectedItem;
    NavigationService.Navigate(new Uri("/details.xaml?UID=" + univObj.UID + "&NAME=" + univObj.Name + "&RANK=" + univObj.Rank,UriKind.Relative));
    

您可以在下一页中检索这些值:

NavigationContext.QueryString["UID"].ToString;