我有一个带有CommandBar的Grid。我只想在指针悬停网格或任何子组件时显示CommandBar。
我通过在PointerEntered事件中将IsOpen设置为true来显示CommandBar。不幸的是,打开的CommandBar正在吞下PointerExited事件,我无法关闭CommandBar。
我发现的事情:
什么是吞噬我的指针事件,我该如何预防?或者你对我的问题有不同的解决方案吗?
这是一个简化的例子:
<!-- Some content -->
<!-- Grid with command bar -->
<Grid Height="300" Width="700" PointerEntered="Grid_PointerEntered" PointerExited="Grid_PointerExited" BorderBrush="Black" BorderThickness="1">
<!-- Template just set Visibility of "MoreButton" to Collapsed (hiding it because it is not needed if you have hover ability) -->
<CommandBar VerticalAlignment="Bottom" Canvas.ZIndex="1" x:Name="uxCommandBar" Template="{StaticResource CommandBarControlTemplate1}">
<!-- Buttons -->
</CommandBar>
<!-- Other content stuff - here a Canvas for providing a hoverable area -->
<Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Red"></Canvas>
</Grid>
答案 0 :(得分:1)
有两件事情会浮现在脑海中:
<Page>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid PointerEntered="Grid_PointerEntered" PointerExited="Grid_PointerExited">
<CommandBar x:Name="bar" IsSticky="True" VerticalAlignment="Bottom">
<AppBarButton Icon="Accept" Label="Done"/>
</CommandBar>
</Grid>
</Grid>
</Page>
private void Grid_PointerEntered(object sender, PointerRoutedEventArgs e)
{
bar.IsOpen = true;
}
private void Grid_PointerExited(object sender, PointerRoutedEventArgs e)
{
bar.IsOpen = false;
}