如何从Windows Phone 7应用程序中的列表框导航

时间:2014-02-06 12:13:16

标签: c# xaml windows-phone-7 listbox

我正在为Windows Phone 7构建一个应用程序,我在ListBox中显示来自Web服务的数据 WebService包含以下数据: 新闻标题,新闻描述,日期开始和图像路径 在列表框中,我显示新闻标题,日期开始和图像路径 现在点击列表框中的项目,我想导航到另一个页面,该页面应显示所有三个细节以及新闻描述。

我的xaml是:

<ListBox Name="listBox1" SelectionChanged="listBox1_SelectionChanged">
           <!-- SelectionChanged="listBox1_SelectionChanged"-->
            <ListBox.ItemTemplate>
            <DataTemplate>
                    <Button>
                        <Button.Content>
                       <ScrollViewer HorizontalScrollBarVisibility="Auto" Height="80" Width="400">
                           <StackPanel Orientation="Horizontal" Margin="0,0,0,0">
                                    <Image Source="{Binding ImageBind }" Height="80" Width="120"/>
                                    <StackPanel Orientation="Vertical">
                                  <TextBlock Text="{Binding Path=News_Title}" TextWrapping="Wrap"></TextBlock>
                                 <!-- <TextBlock Text="{Binding Path=News_Description}" TextWrapping="Wrap"></TextBlock>-->
                                        <TextBlock Text="{Binding Path=Date_Start}" TextWrapping="Wrap" ></TextBlock>
                                     </StackPanel>
                                  </StackPanel>
                            </ScrollViewer>
                        </Button.Content>
                    </Button>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

.cs文件是:

 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;
}

现在在新页面中说newsdetails.xaml我想从这个页面导航并显示完整的细节 请帮忙。
因为我是这个领域的新人,所以我陷入了困境 如果这样做,我几乎已经完成了我的应用程序。

 private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (listBox1.SelectedIndex == -1)
            return;
        var item = listBox1.SelectedItem as Newss;
        if (!IsolatedStorageSettings.ApplicationSettings.Contains("SelectedObject"))
        {
            IsolatedStorageSettings.ApplicationSettings["SelectedObject"] = item;
            NavigationService.Navigate(new Uri("/NewsDetails.xaml", UriKind.Relative));
        }
    }

1 个答案:

答案 0 :(得分:0)

在列表框选择更改事件所在的页面中定义静态全局变量:

public static string title;
public static string news_description;

在列表框选择更改时分配以下变量:

private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (listBox1.SelectedIndex == -1)
            return;
        var item = listBox1.SelectedItem as Newss;
        if (!IsolatedStorageSettings.ApplicationSettings.Contains("SelectedObject"))
        {
            IsolatedStorageSettings.ApplicationSettings["SelectedObject"] = item;
            title=item.News_Title;
            news_description=item.News_Description;
            NavigationService.Navigate(new Uri("/NewsDetails.xaml", UriKind.Relative));
        }
    }

在您的导航中,NewsDetails.cs页面访问以下这些项目:

string Title=YourPageName.title;//
string Description=YourPageName.news_description;

根据需要显示这些值