0

我的 WP7 应用程序中有我的 ListPicker 的代码,

    <toolkit:ListPicker x:Name="listTab1" Header="Muti-View 1 Settings"  Margin="428,220,112,25.51" RenderTransformOrigin="0.5,0.5">
                        <toolkit:ListPicker.RenderTransform>
                            <CompositeTransform Rotation="-90"/>
                        </toolkit:ListPicker.RenderTransform>
                        <toolkit:ListPickerItem Content="tab 1"/>
                        <toolkit:ListPickerItem Content="tab 2"/>
                        <toolkit:ListPickerItem Content="tab 3"/>
                    </toolkit:ListPicker>

我需要在 Listpicker 中检测选择了哪个 Listpicker 项目,以便我可以在 If 语句中使用它

我可以实现这一点的任何想法?

4

1 回答 1

0

您需要订阅该ListPicker SelectionChanged事件。首先,我们将获得对当前SelectedItem数据对象的引用,然后我们将获得SelectedItem对类型为 . 的容器的引用ListPickerItem

private void listPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
   //Get the data object that represents the current selected item
   SampleData data = (sender as ListPicker).SelectedItem as SampleData;

   //Get the selected ListPickerItem container instance    
   ListPickerItem selectedItem = this.listPicker.ItemContainerGenerator.ContainerFromItem(data) as ListPickerItem;
}

资源

于 2013-05-02T07:11:25.167 回答