如何让列表框选中的项目值传递到Windows Phone 7的另一个页面?

时间:2013-03-22 08:49:46

标签: windows-phone-7 c#-4.0 linq-to-xml

您正在使用下面给出的xaml文件。我想获取所选项目值到详细信息视图。

<StackPanel Width="Auto">
<StackPanel VerticalAlignment="Top" Width="Auto">
    <ListBox ItemsSource="{Binding Images}"  Width="Auto" ScrollViewer.VerticalScrollBarVisibility="Disabled" SelectionChanged="NotchsList11_SelectionChanged">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
             <StackPanel Orientation="Horizontal"  VerticalAlignment="Top">
            </StackPanel>
                </ItemsPanelTemplate>
                   </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                       <DataTemplate>
                          <Border BorderBrush="White" Margin="0,0,8,0" BorderThickness="1">
                            <Image Source="{Binding}" Width="152" Height="90"  Stretch="Fill"  VerticalAlignment="Top"></Image>
                          </Border>
                            </DataTemplate>
                                </ListBox.ItemTemplate>
                         </ListBox>
                      </StackPanel>
                     <StackPanel Orientation="Horizontal"  VerticalAlignment="Top"  ScrollViewer.VerticalScrollBarVisibility="Disabled" Width="Auto">
                    <ListBox ItemsSource="{Binding Titles}"   ScrollViewer.VerticalScrollBarVisibility="Disabled" SelectionChanged="NotchsList11_SelectionChanged">
                   <ListBox.ItemsPanel>
                         <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal">
                        </StackPanel>
                          </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                               <ListBox.ItemTemplate>
                                    <DataTemplate >
                                        <Border BorderBrush="White" Margin="0,0,8,0"
                                            BorderThickness="1"> 
                                       <TextBlock Text="{Binding}"  Width="152" Height="80" Padding="5,10,0,0"  TextWrapping="Wrap"></TextBlock>    
                                        </Border>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                    </StackPanel>
                    </StackPanel>

My Main.Cs Code

private void NotchsList11_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {

            NavigationService.Navigate(new Uri("/Test.xaml?parameter={0}",UriKind.Relative));
            //NavigationService.Navigate(new Uri("/Page1.xaml?parameter=test", UriKind.Relative));
        }

    }   

我用这个东西我不能去选择项目的其他页面。 我想要输出如下图所示 enter image description here

1 个答案:

答案 0 :(得分:1)

简单有效的方法 - 拥有ViewModel。选择项目后(挂钩SelectionChanged事件处理程序),将实例传递给ViewModel并导航到将显示项目详细信息的第二页。确保页面绑定到ViewModel,然后只读取您传入的项目。