Reputation: 419
Is there any way to find out witch Item
number is under the pointer on GridView
? I like to show short information about the item under the mouse without selecting the item by any click.
Upvotes: 0
Views: 478
Reputation: 169370
You could handle the PointerEntered
and PointerExited
events for the root element in your 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" />
Code:
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;
}
Upvotes: 4