小编dam*_*atx的帖子

如何访问我选择的项目?列表框

我在我的xaml页面上有一个名为MainListBox的ListBox.我可以获得被选中的索引,但是如何从所选项中获取数据?

我的MainListBox_SelectionChanged:

private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        int noteID1 = MainListBox.SelectedIndex+1;

        if (MainListBox.SelectedIndex != null)
        {


            //I can get the index that get selected, 
            Debug.WriteLine(MainListBox.SelectedIndex);



        }

         MainListBox.SelectedIndex = -1;

    }
Run Code Online (Sandbox Code Playgroud)

我的XAML:

<ListBox x:Name="MainListBox" Margin="6,0,0,0" ItemsSource="{Binding Items}" SelectionChanged="MainListBox_SelectionChanged" Height="578" VerticalAlignment="Bottom" Grid.ColumnSpan="3">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Margin="0,0,0,17" Width="432">
                        <TextBlock x:Name="ItemText" Text="{Binding noteName}" Margin="-2,-13,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                        <TextBlock x:Name="DetailsText" Text="{Binding noteText}" Margin="10,-6,0,3" Style="{StaticResource PhoneTextSubtleStyle}"/>
                        <TextBlock x:Name="noteIdText" Text="{Binding noteID}" Margin="10,-6,0,3" Style="{StaticResource PhoneTextSubtleStyle}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
Run Code Online (Sandbox Code Playgroud)

请有人指导我,谢谢.:)

xaml listbox windows-phone-7

3
推荐指数
1
解决办法
7340
查看次数

标签 统计

listbox ×1

windows-phone-7 ×1

xaml ×1