猿问

XAML UWP AppBar 没有响应

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


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


据我所知,当我删除代码中的“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>

这是第一次导航到页面时


不工作:

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

预期行为

http://img4.mukewang.com/63708df40001c1c306380129.jpg

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



慕神8447489
浏览 124回答 2
2回答

千巷猫影

官方文档中有备注,只有在升级使用 AppBar 的 Universal Windows 8 应用时才应该使用 AppBar,并且需要尽量减少改动。对于 Windows 10 中的新应用,我们建议改用该CommandBar控件。请尝试CommandBar如下使用。<CommandBar>&nbsp; &nbsp; <AppBarButton Label="Reset" Icon="AllApps" Click="ButtonResetGrid" />&nbsp; &nbsp; <AppBarButton Label="Export" Icon="AllApps" Click="ButtonExport" />&nbsp; &nbsp; <AppBarButton Label="Refresh" Icon="AllApps" Click="ButtonRefreshCode" />&nbsp; &nbsp; <CommandBar.SecondaryCommands>&nbsp; &nbsp; &nbsp; &nbsp; <AppBarButton Icon="Like" Label="Like" />&nbsp; &nbsp; &nbsp; &nbsp; <AppBarButton Icon="Dislike" Label="Dislike" />&nbsp; &nbsp; </CommandBar.SecondaryCommands>&nbsp; &nbsp; <CommandBar.Content>&nbsp; &nbsp; &nbsp; &nbsp; <TextBlock Text="Now playing..." Margin="12,14"/>&nbsp; &nbsp; </CommandBar.Content></CommandBar>更新如果你想让所有 AppBarButtons conllection 离开,你需要像链接一样自定义 CommandBar 样式。

慕森卡

你能试试吗,因为它可能会起作用:&nbsp;<Page.TopAppBar>&nbsp; &nbsp; &nbsp; &nbsp; <AppBar x:Name="AppBar" IsSticky="True" Margin="0,0,0,0"&nbsp; IsOpen="True">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <StackPanel Orientation="Horizontal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Button Content="Reset" Width="140" Height="80" Click="ButtonResetGrid_Click"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Button Content="Export" Width="140" Height="80" Icon="AllApps" Click="ButtonExport_Click"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Button Content="Refresh" Width="140" Height="80" Icon="AllApps" Click="ButtonRefreshCode_Click"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </StackPanel>&nbsp; &nbsp; &nbsp; &nbsp; </AppBar>&nbsp; &nbsp; </Page.TopAppBar>
随时随地看视频慕课网APP
我要回答