繁体   English   中英

用于wp8的longlistselector工具

[英]longlistselector tool for wp8

我目前正在使用Longlistselector Windows Phone 8。 我正在列出我的产品列表,我需要获取所选项目索引,使用我需要导航到相应页面的索引。 如何从longlistselector获取所选索引? 我正在获取selectedItem ,但我不知道如何使用selecteditem获取其索引? 提前致谢

我的长列表选择器代码是

<phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Key="trainlistitemtemplate">
            <StackPanel Orientation="Horizontal">
                <Image Height="170" Width="170" Source="{Binding Imgcity}" Margin="0,0,9,0"></Image>
                <StackPanel VerticalAlignment="Top">
                    <TextBlock FontWeight="Bold" Text="{Binding Cityname}" />
                    <TextBlock Text="{Binding Citycode}"/>
                    <Button Content="BOOK" BorderBrush="{x:Null}" Background="{StaticResource PhoneAccentBrush}" Click="Button_Click_1"></Button>
                </StackPanel>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Name="grpheadtemplate">
            <Border Background="Transparent" Padding="5">
                <Border Background="{StaticResource PhoneAccentBrush}" BorderBrush="{StaticResource PhoneAccentBrush}" BorderThickness="2" Width="62" 
                        Height="62" Margin="0,0,18,0" HorizontalAlignment="Left">
                    <TextBlock Text="{Binding Key}" Foreground="{StaticResource PhoneForegroundBrush}" FontSize="48" Padding="6" 
                                FontFamily="{StaticResource PhoneFontFamilySemiLight}" HorizontalAlignment="Left" VerticalAlignment="Center">
                    </TextBlock>
                </Border>
            </Border>
        </DataTemplate>

        <phone:JumpListItemBackgroundConverter x:Key="BackgroundConverter"/>
        <phone:JumpListItemForegroundConverter x:Key="ForegroundConverter"/>
        <Style x:Key="trainlist" TargetType="phone:LongListSelector">
            <Setter Property="GridCellSize"  Value="113,113"/>
            <Setter Property="LayoutMode" Value="Grid" />
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Border Background="{Binding Converter={StaticResource BackgroundConverter}}" Width="113" Height="113" Margin="6" >
                            <TextBlock Text="{Binding Key}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" FontSize="48" Padding="6" 
               Foreground="{Binding Converter={StaticResource ForegroundConverter}}" VerticalAlignment="Center"/>
                        </Border>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </phone:PhoneApplicationPage.Resources>
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="Select Destination" Style="{StaticResource PhoneTextNormalStyle}" FontSize="40" FontFamily="Batang" FontWeight="Bold"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->

        <Grid Grid.Row="1">
            <phone:LongListSelector HorizontalAlignment="Left" Height="703" Margin="10,10,0,-36" VerticalAlignment="Top" Width="458" x:Name="lls1"
                                    Background="Transparent" HideEmptyGroups="True" LayoutMode="List" IsGroupingEnabled="True"
                                    ItemTemplate="{StaticResource trainlistitemtemplate}" GroupHeaderTemplate="{StaticResource grpheadtemplate}"
                                    JumpListStyle="{StaticResource trainlist}" MouseLeftButtonDown="lls1_MouseLeftButtonDown" SelectionChanged="lls1_SelectionChanged"/>
        </Grid>
    </Grid>

你真正想要的不是索引,而是让用户点击项目的DataContext 我想,您正在使用数据绑定来填充LongListSelector。 然后,您需要在列表项上侦听Tap事件,并且在该事件的处理程序中,您需要检索DataContext属性,将其DataContext为所需类型,并使用该值来决定要转到哪个页面。 这已在StackOverflow上多次讨论,例如,请参阅答案。

sender是longlistselector,selected ites是特殊的属性,例如:var t =(sender as LongListSelector).SelectedItem as Sample;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM