在 UWP 中隐藏 BottomAppBar(Windows 10)
Hiding BottomAppBar in UWP(Windows 10)
我试图在我的应用程序中隐藏仅供管理员使用的 BottomAppBar。
我希望 BottomAppBar 在我启动后隐藏起来,只有在我右键单击鼠标时才会出现。
目前,当我启动我的应用程序时,应用栏以最小化模式显示,如下所示:
Image
希望完全隐藏,让用户不知道有设置page/bottomAppBar。
这是我的代码:
<Page.BottomAppBar>
<AppBar Background="{StaticResource CitiKioskBackgroundBrush}"
IsOpen="False"
IsSticky="False">
<StackPanel Orientation="Horizontal">
<AppBarButton Name="SettingAppBarButton"
Click="SettingAppBarButton_Click"
Icon="Setting"
Label="Settings"
Foreground="White"/>
</StackPanel>
</AppBar>
</Page.BottomAppBar>
您可以将底部应用栏的可见性设置为 Collapsed
,然后在页面的 loaded event
中写入逻辑以识别管理员用户并将可见性设置为 Visible
..所以你可以做这样的事情..
XAML
<Page.BottomAppBar>
<AppBar x:Name="appBarName" <!-- Added Name -->
Visibility="Collapsed" <!-- Changed default Visibility -->
Background="{StaticResource CitiKioskBackgroundBrush}"
IsOpen="False"
IsSticky="False"
Visibility="Collapsed">
<StackPanel Orientation="Horizontal">
<AppBarButton Name="SettingAppBarButton"
Click="SettingAppBarButton_Click"
Icon="Setting"
Label="Settings"
Foreground="White"/>
</StackPanel>
</AppBar>
</Page.BottomAppBar>
C#(后面的代码)
private void Page_Loaded(object sender, RoutedEventArgs e)
{
if(admin)//your logic here to identify admin user
appBarName.Visibility = Visibility.Visible;
}
编辑
您可以将以下代码添加到您想要的任何事件处理程序,例如按钮单击或 RightTapped 事件..
Updated Code for toggling visibility
bool toggle=false;
//Code for toggling your app bar visibility
private void UserControl_RightTapped(object sender, RoutedEventArgs e)
{
if(toggle)
{
appBarName.Visibility = Visibility.Visible;
toggle=false;
}else{
appBarName.Visibility = Visibility.Collapsed;
toggle=true;
}
}
我试图在我的应用程序中隐藏仅供管理员使用的 BottomAppBar。
我希望 BottomAppBar 在我启动后隐藏起来,只有在我右键单击鼠标时才会出现。
目前,当我启动我的应用程序时,应用栏以最小化模式显示,如下所示:
Image
希望完全隐藏,让用户不知道有设置page/bottomAppBar。
这是我的代码:
<Page.BottomAppBar>
<AppBar Background="{StaticResource CitiKioskBackgroundBrush}"
IsOpen="False"
IsSticky="False">
<StackPanel Orientation="Horizontal">
<AppBarButton Name="SettingAppBarButton"
Click="SettingAppBarButton_Click"
Icon="Setting"
Label="Settings"
Foreground="White"/>
</StackPanel>
</AppBar>
</Page.BottomAppBar>
您可以将底部应用栏的可见性设置为 Collapsed
,然后在页面的 loaded event
中写入逻辑以识别管理员用户并将可见性设置为 Visible
..所以你可以做这样的事情..
XAML
<Page.BottomAppBar>
<AppBar x:Name="appBarName" <!-- Added Name -->
Visibility="Collapsed" <!-- Changed default Visibility -->
Background="{StaticResource CitiKioskBackgroundBrush}"
IsOpen="False"
IsSticky="False"
Visibility="Collapsed">
<StackPanel Orientation="Horizontal">
<AppBarButton Name="SettingAppBarButton"
Click="SettingAppBarButton_Click"
Icon="Setting"
Label="Settings"
Foreground="White"/>
</StackPanel>
</AppBar>
</Page.BottomAppBar>
C#(后面的代码)
private void Page_Loaded(object sender, RoutedEventArgs e)
{
if(admin)//your logic here to identify admin user
appBarName.Visibility = Visibility.Visible;
}
编辑
您可以将以下代码添加到您想要的任何事件处理程序,例如按钮单击或 RightTapped 事件..
Updated Code for toggling visibility
bool toggle=false;
//Code for toggling your app bar visibility
private void UserControl_RightTapped(object sender, RoutedEventArgs e)
{
if(toggle)
{
appBarName.Visibility = Visibility.Visible;
toggle=false;
}else{
appBarName.Visibility = Visibility.Collapsed;
toggle=true;
}
}