如何在网格视图中确定单击的项目

时间:2019-10-21 01:37:13

标签: c++ xaml uwp winrt-xaml c++-winrt

给出一个GridView,例如

<GridView IsItemClickEnabled="True"  ItemClick="favorite_clicked" ItemsSource="{x:Bind MainViewModel.FavoriteBinders}" Grid.Column="1">
    <GridView.ItemTemplate>
        <DataTemplate   x:DataType="local:FavoriteBinder">
            <StackPanel AccessKey="{x:Bind CedictId, Mode=OneWay}"  Width="200" Margin="20">
            <TextBlock   Text="{x:Bind Simplified, Mode=OneWay}" FontWeight="Bold" 
              />
            <TextBlock Text="{x:Bind Pinyin, Mode=OneWay}" TextWrapping="NoWrap" 
                />
        </StackPanel>
    </DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemsPanel>
    <ItemsPanelTemplate>
            <ItemsWrapGrid MaximumRowsOrColumns="7"/>
    </ItemsPanelTemplate>
</GridView.ItemsPanel>

其中填充了类型FavoriteBinder,该类型具有一个名为id的int32_t字段。

还有一个点击功能,如下所示:

void FavoritesPage::favorite_clicked(
    Windows::Foundation::IInspectable const& sender, 
    Windows::UI::Xaml::RoutedEventArgs const& args) 
{
}

如何获取我在favourite_clicked函数中被点击的商品的ID?

1 个答案:

答案 0 :(得分:2)

在favorite_clicked事件中,可以通过 e.ClickedItem()方法获取单击的FavoriteBinder类,并使用 .as 方法将对象转换为FavoriteBinder类型。

SELECT MEAN(value) FROM tbl WHERE name = 'Olli' -- all time mean, used directly in final query 

-- for the short term mean I use a CTE:
WITH short_term_tbl AS (SELECT * FROM tbl WHERE name = 'Olli' ORDER BY Date DESC LIMIT 3)
    SELECT MEAN(short_term_tbl.value) / MEAN(table.value)
    FROM short_term_tbl, tbl