我想自动隐藏汉堡菜单按钮,以便从页面顶部到底部显示菜单。为此,我尝试将 HamburgerButtonVisibility 绑定到 IsPaneOpen 属性:
<controls:HamburgerMenu x:Name="Menu" VisualStateNarrowMinWidth="0" HamburgerBackground="White" HamburgerForeground="Black"
NavAreaBackground="{StaticResource MenuBackground}"
HamburgerButtonVisibility="{x:Bind Menu.IsOpen, Mode=OneWay, Converter={StaticResource ReverseBooleanToVisibilityConverter}}" />
但是使用此解决方案存在一个问题:当我打开菜单并在菜单外点击时,菜单已关闭,但汉堡按钮消失了。
有没有其他解决方案?
如果菜单属于页面(不是外壳),我也没有找到如何将 NavigationService 设置为 HamburgerMenu 。我尝试使用页面 ViewModel 设置它,但在这种情况下我得到了 NRE:
<Page
x:Class="App.LoginPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:App.ViewModels"
mc:Ignorable="d">
<Page.DataContext>
<vm:LoginViewModel />
</Page.DataContext>
<controls:HamburgerMenu x:Name="Menu" />
</Page>
sealed partial class LoginPage : Page
{
public LoginPage ()
{
this.InitializeComponent ();
Menu.NavigationService = ViewModel.NavigationService; //NRE here
}
public LoginViewModel ViewModel => DataContext as LoginViewModel;
}
堆栈跟踪:
at Template10.Controls.HamburgerMenu.set_NavigationService(INavigationService value)
at App.LoginPage..ctor()
at App.App_XamlTypeInfo.XamlTypeInfoProvider.Activate_46_LoginPage()
at App.App_XamlTypeInfo.XamlUserType.ActivateInstance()