XAML UWP AppBar 没有响应

XAML UWP AppBar not responding

我的 UWP 应用程序出现奇怪的行为。

我的页面顶部有一个带有三个按钮的 AppBar。当我通过 NavView 导航到我的页面时,AppBar 没有响应,按钮和菜单(三个点)都没有响应,也没有 "mouseover"。当我再次导航到该页面时,它工作正常。

据我所知,当我删除代码中的 "isOpen" 属性 时,它似乎可以正常工作。一旦我设置 属性(在 C# 或 XAML 代码中),它在第一次导航时没有响应

<AppBar x:Name="AppBar" IsSticky="True" Margin="0,0,0,0"  IsOpen="True" >
  <StackPanel Orientation="Horizontal">
    <AppBarButton Label="Reset" Icon="AllApps" Click="ButtonResetGrid" />
    <AppBarButton Label="Export" Icon="AllApps" Click="ButtonExport" />
    <AppBarButton Label="Refresh" Icon="AllApps" Click="ButtonRefreshCode" />
  </StackPanel>
</AppBar>

这是第一次导航到该页面时

不工作:

第二次导航后(您可以看到鼠标悬停):

预期行为

也许有人有想法或好的提示。

你能试试吗,它可能会起作用:

 <Page.TopAppBar>
        <AppBar x:Name="AppBar" IsSticky="True" Margin="0,0,0,0"  IsOpen="True">
                <StackPanel Orientation="Horizontal">
                    <Button Content="Reset" Width="140" Height="80" Click="ButtonResetGrid_Click"/>
                    <Button Content="Export" Width="140" Height="80" Icon="AllApps" Click="ButtonExport_Click"/>
                    <Button Content="Refresh" Width="140" Height="80" Icon="AllApps" Click="ButtonRefreshCode_Click"/>
                </StackPanel>

        </AppBar>
    </Page.TopAppBar>

remarks in official document, You should use the AppBar only when you are upgrading a Universal Windows 8 app that uses the AppBar, and need to minimize changes. For new apps in Windows 10, we recommend using the CommandBar控件代替。请尝试使用 CommandBar 如下所示。

<CommandBar>
    <AppBarButton Label="Reset" Icon="AllApps" Click="ButtonResetGrid" />
    <AppBarButton Label="Export" Icon="AllApps" Click="ButtonExport" />
    <AppBarButton Label="Refresh" Icon="AllApps" Click="ButtonRefreshCode" />
    <CommandBar.SecondaryCommands>
        <AppBarButton Icon="Like" Label="Like" />
        <AppBarButton Icon="Dislike" Label="Dislike" />
    </CommandBar.SecondaryCommands>

    <CommandBar.Content>
        <TextBlock Text="Now playing..." Margin="12,14"/>
    </CommandBar.Content>
</CommandBar>

更新

如果你想让所有 AppBarButtons conllection 离开,你需要像 link 一样自定义 CommandBar 样式。