In order to make a hamburger button in a UWP application, I try to use BooleanToVisibilityConverter
to change the state of the hamburger button, just like RSSReader Example.
The problem is, when I created BooleanToVisibilityConverter.cs in the folder Common and wrote:
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
namespace UWPTest.Common {
public class BooleanToVisibilityConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, string language) =>
(bool)value ^ (parameter as string ?? string.Empty).Equals("Reverse") ?
Visibility.Visible : Visibility.Collapsed;
public object ConvertBack(object value, Type targetType, object parameter, string language) =>
(Visibility)value == Visibility.Visible ^ (parameter as string ?? string.Empty).Equals("Reverse");
}
}
then import it into MainPage.xaml :
<Page
x:Class="UWPTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UWPTest"
xmlns:common="using:UWPTest.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<common:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</Page.Resources>
<Grid Background="Transparent">
<ToggleButton x:Name="TogglePaneButton"
Visibility="{x:Bind ViewModel.IsInDetailsMode, Mode=OneWay, ConverterParameter=Reverse, Converter={StaticResource BooleanToVisibilityConverter}}"
Margin="0"
TabIndex="1"
Checked="{x:Bind CheckTogglePaneButtonSizeChanged}"
Unchecked="{x:Bind CheckTogglePaneButtonSizeChanged}"
IsChecked="{Binding IsPaneOpen, ElementName=RootSplitView, Mode=TwoWay}"
AutomationProperties.Name="Menu" ToolTipService.ToolTip="Menu"
Style="{StaticResource SplitViewTogglePaneButtonStyle}"/>
</Grid>
</Page>
IntelliSense says The name "BooleanToVisibilityConverter" does not exist in the namespace "using:UWPTest.Common". I can't figure out the reason why the class is not found.
The picture of IntelliSense's words in Chinese:
Visibility="{x:Bind ViewModel.IsInDetailsMode, Mode=OneWay}"
should work. – Algor