I have already checked Simulating a mousehover effect on a fontIcon in uwp. But I am facing a different, "flickering" issue.
I have a Grid inside a ScrollViewer, which is a child of a PivotItem control. The grid is empty at the beginning and then programmatically populated.
<PivotItem>
<ScrollViewer x:Name="MyScrollBar" >
<Grid Name="MyGrid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
</Grid>
</ScrollViewer>
</PivotItem>
The columns are then filled with 3 TextBlocks each. My goal is to show a Flyout with additional details when hovering over a row (not a single TextBlock). To achieve this, I define for each row an additional transparent Rectangle whose ColumnSpan is 3, and add it as the last child of each row. I then give it a Flyout as follows:
Rectangle rect = new Rectangle();
rect.Opacity = 0;
rect.SetValue(Grid.RowProperty, r);
rect.SetValue(Grid.ColumnSpanProperty, 3);
Flyout fl = new Flyout();
Grid flGrid = new Grid();
TextBlock flTb1 = new TextBlock();
flTb1.Text = details.Name;
flGrid.Children.Add(flTb1);
fl.Content = flGrid;
rect.SetValue(FlyoutBase.AttachedFlyoutProperty, fl);
rect.PointerEntered += Rect_PointerEntered;
rect.PointerExited += Rect_PointerExited;
rect.Margin = new Thickness(2);
Here the PointerEntered and PointerExited event handlers:
private void Rect_PointerEntered(object sender, PointerRoutedEventArgs e)
{
((Flyout)(((Rectangle)sender).GetValue(FlyoutBase.AttachedFlyoutProperty))).ShowAt((Rectangle)sender);
}
private void Rect_PointerExited(object sender, PointerRoutedEventArgs e)
{
((Flyout)(((Rectangle)sender).GetValue(FlyoutBase.AttachedFlyoutProperty))).Hide();
}
As the pointer enters the hit zone of a grid row, suddenly the Flyout appears and disappears. And so it does whenever the pointer moves, even over the same row (I don't want the Flyout to disappear when moving the pointer over the same row). The result is a flickering flyout. It seemes to me that the PointerEntered/PointerExited events are both fired at any point hovered.
What I have already tried:
- Handle the PointerEntered only (I know this is not best practice, but I tried)
- Set PointerEntered.Handled to false (I thought that maybe the other controls in the grid were impacting the behavior)
- Handle the PointerMoved only
- Stored the "hovered" and "hovering" Rectangle(s) to recognize when the pointer is above the same/another row
- A lot of other attempts I don't even remember... always getting the same flickering results.
Could anyone point me in the right direction? Thank you in advance!