我的UWP App中有一个奇怪的行为。
我有一个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>
这是第一次导航到页面时
导航第二次后(你可以看到鼠标悬停):
也许某人有一个想法或一个好的暗示。
官方文档中有remarks,只有在升级使用AppBar的通用Windows 8应用程序时才应使用AppBar,并且需要尽量减少更改。对于Windows 10中的新应用程序,我们建议使用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,你需要自定义CommandBar样式,如link。
你可以尝试一下,它可能会起作用:
<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>