getting information from a data binding listBox for a new page

匆匆过客 提交于 2019-12-13 06:39:34

问题


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>

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?

Plz help me. Thanks,


回答1:


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

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



来源:https://stackoverflow.com/questions/6800542/getting-information-from-a-data-binding-listbox-for-a-new-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!