【问题标题】:Get the index of a tapped item in AdaptiveGridView UWP在 AdaptiveGridView UWP 中获取点击项的索引
【发布时间】:2016-09-09 10:23:16
【问题描述】:

有没有办法在 AdaptiveGridView 工具包中获取被点击项目的索引。 这是我的代码: 页面资源:

<Page.Resources>
    <DataTemplate x:Key="Photos">
        <Grid>
            <Image Source="{Binding ImageURL}"
                       Stretch="UniformToFill"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center">
            </Image>
            <TextBlock Text="{Binding ImageText}"
                       FontSize="20">
            </TextBlock>
        </Grid>
    </DataTemplate>
</Page.Resources>

XAML:

  <UWPToolkit:AdaptiveGridView x:Name="AdaptiveGV" ItemHeight="200" ItemClick="AdaptiveGV_ItemClick" DesiredWidth="200" ItemTemplate="{StaticResource Photos}"/>

后面的代码:

    List<Images>   ImageCollection = new List<Images>();

ImageCollection.Add(new Images()
                    {
                        ImageURL = Response[i].ProjectImageURL,
                        ImageText = Response[i].ProjectName

                    });
                }
                AdaptiveGV.ItemsSource = ImageCollection;

我想要获取我点击的项目的索引。有没有办法做到这一点?

【问题讨论】:

  • 有一个ItemClickCommand 属性我假设你可以启动一个类似于collection.IndexOf(clickedItem) 的 indexOf 方法,但我还没有使用过那个 AdaptiveGridView,只是想我会发表评论,因为没有人回答但作为一条可能的路线。

标签: c# xaml uwp


【解决方案1】:

我想要获取我点击的项目的索引。有没有办法做到这一点?

是的,你可以,在ItemClickEventArgs,你可以像这样获取点击的项目及其索引:

private void AdaptiveGV_ItemClick(object sender, ItemClickEventArgs e)
{
    var item = e.ClickedItem as Images;
    var index = ImageCollection.IndexOf(item);
}

【讨论】:

    猜你喜欢
    • 2017-11-04
    • 2017-11-20
    • 1970-01-01
    • 2017-02-08
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 1970-01-01
    • 2011-04-15
    相关资源
    最近更新 更多