Windows App 8.1 StackPanel 鼠标悬停

Windows App 8.1 StackPanel Mouse-Over

我在 Windows 8.1 应用程序上有一个 StackPanel,我想添加一个 Mouse-Over 功能。 如果我理解正确,Windows 8.1 应用程序的类似功能是 PointerEntered/PointerExited。例如,如何使用这些函数获取 TextBlock 的 "Item's" 文本?

编辑:我基本上想在鼠标悬停时获取 TextBlock 的句柄,这样我就可以获取或设置它的属性(文本等...)。

这是我的C#函数

private void itemGridView_PointerEntered(object sender, PointerRoutedEventArgs e)
    {

    }

和我的 xaml 代码:

<GridView
        x:Name="itemGridView"
        AutomationProperties.AutomationId="ItemGridView"
        AutomationProperties.Name="Items In Group"
        TabIndex="1"
        Grid.RowSpan="2"
        Padding="120,126,120,50"
        ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
        SelectionMode="None"
        IsSwipeEnabled="false"
        IsItemClickEnabled="True"
        ItemClick="ItemView_ItemClick" PointerEntered="itemGridView_PointerEntered">
        <GridView.ItemTemplate>
            <DataTemplate>
                    <Grid Height="110" Width="480" Margin="10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                        <Border Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" Width="110" Height="110">
                            <Image x:Name="ImageItemName" Source="{Binding ImagePath}" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}"/>
                        </Border>
                        <StackPanel x:Name="stackPanel1" Grid.Column="1" VerticalAlignment="Top" Margin="10,0,0,0">
                            <TextBlock x:Name="ItemTitleText" Text="{Binding Title}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="NoWrap"/>
                            <TextBlock Text="{Binding Subtitle}" Style="{StaticResource CaptionTextBlockStyle}" TextWrapping="NoWrap"/>
                            <TextBlock x:Name="ItemDescText" Text="{Binding Description}" Style="{StaticResource BodyTextBlockStyle}" MaxHeight="60"/>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </GridView.ItemTemplate>
            <GridView.Header>
            <StackPanel Width="480" Margin="0,4,14,0">
                <TextBlock x:Name="TitleTextBlock" Text="{Binding Subtitle}" Margin="0,0,0,20" Style="{StaticResource SubheaderTextBlockStyle}" MaxHeight="60"/>
                <Image x:Name="imageName" Source="{Binding ImagePath}" Height="400" Margin="0,0,0,20" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}"/>
                <TextBlock x:Name="DescTextBlock" Text="{Binding Description}" Margin="0,0,0,0" Style="{StaticResource BodyTextBlockStyle}"/>
            </StackPanel>
        </GridView.Header>
        <GridView.ItemContainerStyle>
            <Style TargetType="FrameworkElement">
                <Setter Property="Margin" Value="52,0,0,2"/>
            </Style>
        </GridView.ItemContainerStyle>
    </GridView>

使用 属性 Children 获取 UIElementCollection 个子元素。

Panel.Children property. MSDN

    private void StackPanel_PointerEntered(object sender, PointerRoutedEventArgs e)
    {
        var values = new List<string>();
        var sp = sender as StackPanel;
        if (sp != null)
        {
            foreach (var child in sp.Children)
            {
                var tb = child as TextBlock;
                if (tb != null)
                {
                    values.Add(tb.Text);
                }
            }
        }
    }