我有以下XAML构造。
<Controls:HamburgerMenu x:Name="MyHamburgerMenu">
<Controls:HamburgerMenu.PrimaryButtons>
<Controls:HamburgerButtonInfo x:Name="searchButton">
<FontIcon x:Name="searchButtonIcon" Width="48"
Height="48"
Glyph=""
Visibility="{Binding IsOpen, ???"/>
<AutoSuggestBox PlaceholderText="Search" QueryIcon="Find"/>
<Controls:HamburgerButtonInfo x:Name="searchButton">
</Controls:HamburgerMenu.PrimaryButtons>
</Controls:HamburgerMenu>
当菜单"等法"菜单时,应折叠Fonticon元素。如果菜单不是"等法",则应可见fonticon元素。
凹槽音乐应用具有这样的行为(请参阅带有打开菜单的Groove Music应用中的图像(。绑定的参数是哪些?菜单打开时,在UWP Template10 Hide Hamburger按钮中描述了隐藏汉堡按钮的说明。
我想这是一个模板10。我在template10的shell.xaml页面中尝试了以下内容。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="txt-1" Text="{Binding IsOpen, ElementName=MyHamburgerMenu}" Grid.Row="0"/>
<Controls:HamburgerMenu x:Name="MyHamburgerMenu" Grid.Row="1">
<Controls:HamburgerMenu.PrimaryButtons>
<Controls:HamburgerButtonInfo>
<TextBlock x:Name="txt-2" Text="{Binding IsOpen, ElementName=MyHamburgerMenu}"/>
</Controls:HamburgerButtonInfo>
</Controls:HamburgerMenu.PrimaryButtons>
</Controls:HamburgerMenu>
</Grid>
textblock txt-1显示汉堡的正确状态 isopen 属性,而文本block txt-2是空的。
您可以使用ivalueconverter将等值素转换为可见性
public class BooleanToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return (!(bool)value) ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return value;
}
}
本文解释了ivalueconverter以及如何在XAML中使用它们
https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.data.ivalueconverter
,因此起作用。将绑定更改为 X:bind ,并将其引用为" myhamburgermenu"。
<Controls:HamburgerMenu x:Name="MyHamburgerMenu">
<Controls:HamburgerMenu.PrimaryButtons>
<Controls:HamburgerButtonInfo x:Name="searchButton">
<SymbolIcon Width="48"
Height="48"
Symbol="Find"
Visibility="{x:Bind MyHamburgerMenu.IsOpen, Mode=TwoWay, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=false}"/>
<AutoSuggestBox PlaceholderText="Search" QueryIcon="Find"/>
</Controls:HamburgerButtonInfo>
</Controls:HamburgerMenu.PrimaryButtons>
</Controls:HamburgerMenu>
并使用像这样的可逆布尔值converterter