0

嗨,我正在使用下面给出的 xaml 文件。我有来自列表框中的列表和项目源。我想要将所选数据的页面导航到其他页面。

<ListBox x:Name="NotchsList11"  Grid.ColumnSpan="2"
       Margin="0,0,0,0" Grid.Row="3" HorizontalAlignment="left" Width="720"  Grid.RowSpan="2">
    <ListBox.ItemTemplate>
        <DataTemplate>
              <StackPanel Margin="0,0,0,0"  Grid.ColumnSpan="3" x:Name="ControlsPanel"
                    Grid.Column="0"
                    Height="215"
                    VerticalAlignment="Top">
                    <StackPanel Background="#eb2427" Orientation="Horizontal">
                        <TextBlock Grid.Row="1"  FontFamily="Calibri" FontSize="34" FontWeight="Bold"  FontStyle="Normal" Margin="10,0,0,0"
                            Text="{Binding name}"
                               />               
                    </StackPanel>
                    <StackPanel VerticalAlignment="Top" Width="Auto">
                          <ListBox ItemsSource="{Binding Images}" SelectionChanged="NotchsList11_SelectionChanged"></ListBox>
               </StackPanel>
             </StackPanel>
        </ScrollViewer>         
      </StackPanel>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox> 

我的 xaml.cs 代码

private void NotchsList11_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
   Notch selectedItemData  = NotchsList11.SelectedItem as Notch;
    if (selectedItemData != null)
    {
        NavigationService.Navigate(new Uri(string.Format("/Test.xaml?parameter={0}",selectedItemData.articleid), UriKind.Relative));
    }
}

我尝试了这段代码,但选择的项目数据为空。我在这个问题上苦苦挣扎了很长时间,所以请任何人给我解决方案。

4

1 回答 1

0

在您的代码中,SelectionChanged="NotchsList11_SelectionChanged" 出现在图像列表中,而不是 NotchsList11 列表中。请看修改后的代码:

<ListBox x:Name="NotchsList11"  Grid.ColumnSpan="2"  SelectionChanged="NotchsList11_SelectionChanged"
   Margin="0,0,0,0" Grid.Row="3" HorizontalAlignment="left" Width="720"  Grid.RowSpan="2">
<ListBox.ItemTemplate>
    <DataTemplate>
          <StackPanel Margin="0,0,0,0"  Grid.ColumnSpan="3" x:Name="ControlsPanel"
                Grid.Column="0"
                Height="215"
                VerticalAlignment="Top">
                <StackPanel Background="#eb2427" Orientation="Horizontal">
                    <TextBlock Grid.Row="1"  FontFamily="Calibri" FontSize="34" FontWeight="Bold"  FontStyle="Normal" Margin="10,0,0,0"
                        Text="{Binding name}"
                           />               
                </StackPanel>
                <StackPanel VerticalAlignment="Top" Width="Auto">
                      <ListBox ItemsSource="{Binding Images}" IsHitTestVisible="False"/>
           </StackPanel>
         </StackPanel>
    </ScrollViewer>         
  </StackPanel>
</DataTemplate>

于 2013-04-04T09:35:12.917 回答