从新页面的数据绑定列表框中获取信息 [英] getting information from a data binding listBox for a new page

查看:18
本文介绍了从新页面的数据绑定列表框中获取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个新闻部分,其中包含来自 ViewModel 的 listBox 绑定(包括 listBox)

I have a news section that consist of listBox binding from a ViewModel (listBox include)

<controls:PanoramaItem x:Name="News" Header="News">
<!--Double line list with image placeholder and text wrapping-->
<ListBox x:Name="News_ListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items}"SelectionChanged="SelectNewsItem">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<!--Replace rectangle with image-->
<Rectangle Height="100" Width="100" Fill="#FFE5001b" Margin="12,0,9,0"/>
<StackPanel Width="311">                                    
<TextBlock Name="NewsTitle" Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Name="NewsDetail" Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</controls:PanoramaItem>

我想这样做,当有人点击一个新闻项目时,他会将他带到一个新页面并查看完整信息.我做了 selectionChanged 事件,但不知道如何从绑定中获取新闻信息?

I want to do that when some one click on a news item it takes him to a new page and view the full information. I did the selectionChanged event but I don't know How to get the news information from the binding?

请帮帮我.谢谢,

推荐答案

针对这些情况的典型 SelectionChanged 处理程序应如下所示:

a typical SelectionChanged handler for these cases should look like this:

private void lstItems_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (lstItems.SelectedIndex == -1) return;

    var item = lstItems.SelectedItem as MyClass;
    // do navigation here

    lstItems.SelectedIndex = -1;
}

这是 WP7 Visual Studio 中 DataBound 模板的一部分.

This is a part of DataBound template in visual studio for WP7.

这篇关于从新页面的数据绑定列表框中获取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆