有没有办法找出Item
指针下的女巫GridView
?我想在鼠标下显示有关该项目的简短信息,而无需通过任何单击选择该项目。
答案 0 :(得分:2)
您可以处理PointerEntered
中根元素的PointerExited
和ItemTemplate
个事件。
<强> XAML:强>
<GridView>
<x:Int32>1</x:Int32>
<x:Int32>2</x:Int32>
<x:Int32>3</x:Int32>
<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
</Style>
</GridView.ItemContainerStyle>
<GridView.ItemTemplate>
<DataTemplate>
<Grid PointerEntered="TextBlock_PointerEntered"
PointerExited="TextBlock_PointerExited"
Background="Transparent">
<TextBlock Text="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
<TextBlock x:Name="tb" />
<强>代码:强>
private void TextBlock_PointerEntered(object sender, PointerRoutedEventArgs e)
{
Panel root = sender as Panel;
var dataObject = root.DataContext;
tb.Text = dataObject.ToString(); //displays the currently pointed number in "tb"
}
private void TextBlock_PointerExited(object sender, PointerRoutedEventArgs e)
{
tb.Text = string.Empty;
}