1

嗨,我正在使用下面给出的 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>

我的 Main.Cs 代码

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

    }   

我用这个东西我不能用选定的项目去其他页面。我想要如下图所示的输出 在此处输入图像描述

4

1 回答 1

1

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

于 2013-03-22T16:34:08.883 回答