【问题标题】:listbox navigation to a new page and displaying data in details in the navigated page in windows phone 7 application列表框导航到新页面并在 Windows Phone 7 应用程序的导航页面中详细显示数据
【发布时间】:2014-02-08 07:27:49
【问题描述】:

我正在 Windows Phone 7 应用程序中构建我的第一个应用程序。我有一些来自 Web 服务的数据,这些数据显示在列表框中。我在列表框中显示的数据是 News_Title、Date_Start、图像。在单击列表框中的项目时,还有另一个数据 News_Description 应与新页面中的数据先前数据一起显示。会有几个数据,所以我需要显示点击的数据。

我的 cs 文件,其中数据显示在 web 服务的列表框中是:

public partial class News : PhoneApplicationPage
{
    public class Newss
    {
        public string News_Title { get; set; }
        public string News_Description { get; set; }
        public string Date_Start { get; set; }
        public string image_path { get; set; }
        public BitmapImage ImageBind{get;set;}

    }

    public News()
    {
        InitializeComponent();

        KejriwalService.aapSoapClient client = new KejriwalService.aapSoapClient();
        client.getarvindNewsCompleted += new EventHandler<KejriwalService.getarvindNewsCompletedEventArgs>(client_getarvindNewsCompleted);
        client.getarvindNewsAsync();

        progressName.Visibility = System.Windows.Visibility.Visible;
    }

    void client_getarvindNewsCompleted(object sender, KejriwalService.getarvindNewsCompletedEventArgs e)
    {
        string result = e.Result.ToString();
        List<Newss> listData = new List<Newss>();
        XDocument doc = XDocument.Parse(result);

        progressName.Visibility = System.Windows.Visibility.Collapsed;

        foreach (var location in doc.Descendants("UserDetails"))
        {
            Newss data = new Newss();

            data.News_Title = location.Element("News_Title").Value;
            //data.News_Description = location.Element("News_Description").Value;
            data.Date_Start = location.Element("Date_Start").Value;
            data.image_path = location.Element("image_path").Value;
            data.ImageBind = new BitmapImage(new Uri( @"http://political-leader.vzons.com/ArvindKejriwal/images/uploaded/"+data.image_path, UriKind.Absolute));

            listData.Add(data);
        }

        listBox1.ItemsSource = listData;
    }

    private void Image_Back(object sender, RoutedEventArgs e)
    {
        NavigationService.Navigate(new Uri("/AAP.xaml", UriKind.Relative));
    }

    private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        // If selected index is -1 (no selection) do nothing

        if (listBox1.SelectedIndex == -1)
            return;

        // Navigate to the new page
        NavigationService.Navigate(new Uri("/NewsDetails.xaml?selectedItem=" + listBox1.SelectedIndex, UriKind.Relative));

        // Reset selected index to -1 (no selection)
        listBox1.SelectedIndex = -1;
    }
}

现在在新闻详细信息页面中,我想详细显示所有四个数据,即 Web 服务中的完整数据。请帮我解决这个问题。

我的新闻详情页面:

namespace KejriwalPhoneApp
{
    public partial class NewsDetails : PhoneApplicationPage
    {
        public NewsDetails()
        {
            InitializeComponent();
        }

        private void Image_Back(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/News.xaml", UriKind.Relative));
        }
    }
}

【问题讨论】:

    标签: c# windows-phone-7 listbox


    【解决方案1】:

    我看到了您的代码,您可以在 listBox1_SelectionChanged 方法中更改您的导航代码:

    Newss news = listBox1.SelectedItem as Newss;
    NavigationService.Navigate(new Uri("/NewsDetails.xaml?News_Title=" + news.News_Title + "&News_Description=" + news.News_Description + "&image_path=" + news.image_path, UriKind.Relative));
    

    并在导航页面上使用这三个参数。

    【讨论】:

    • 请看我现在编辑的代码。我需要在哪里发送参数?
    • 是的,导航时需要发送参数。并且导航页面也需要做某事。比如:var param1 = NavigationContext.QueryString["ParamName"];在 OnNavigatedTo 方法中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多