0

我有以下代码组成 aHubSection内的Hub.

            <HubSection DataContext="{Binding Path=[0], Source={StaticResource groupedItemsViewSource}}" Padding="40,30,40,0">
            <HubSection.Background>
                <ImageBrush ImageSource="Images/BG.jpg" Stretch="UniformToFill" />
            </HubSection.Background>
            <HubSection.Header>
                <TextBlock x:Uid="Section1Header" TextLineBounds="TrimToBaseline" OpticalMarginAlignment="TrimSideBearings" Text="English"/>
            </HubSection.Header>
            <DataTemplate>
                <GridView
                    x:Name="itemGridView1"
                    Margin="-4,-4,0,0"
                    AutomationProperties.AutomationId="ItemGridView"
                    AutomationProperties.Name="Items In Group"
                    ItemsSource="{Binding Items}"
                    ItemTemplate="{StaticResource Standard240x320ItemTemplate}"
                    SelectionMode="Single"
                    IsSwipeEnabled="false"
                    IsItemClickEnabled="True"
                    ItemClick="ItemView_ItemClick">
                </GridView>
            </DataTemplate>
        </HubSection>

我也设置了一个 AppBar,但我不确定如何告诉 AppBar 在 HubSection 中选择了什么。

请指教。

编辑:澄清一下,我在实现代码方面遇到了问题,例如itemGridView1.selectedItem因为我被告知它“在当前上下文中不存在”。

4

1 回答 1

2

大多数关于此问题的建议都集中在遍历 Frame 的可视化树上,但这似乎在 XAML Hub 部分中效果不佳。

相反,在您的 GridView 中实现一个 SelectionChanged 事件。触发此操作后,它将发送 GridView 发送者的详细信息,然后可以参考这些详细信息以获取其他信息,例如 .SelectedItem。

private void GridViewName_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    var GridState = sender as GridView;
    if(GridState.SelectedItems.Count>0)
    {
        // Do something
    }
}
于 2013-11-14T13:25:48.693 回答