【问题标题】:Hide AppBarButton using visibility collapsed使用折叠的可见性隐藏 AppBarButton
【发布时间】:2016-02-07 04:56:54
【问题描述】:

我有一个应用程序可以检查用户是否是管理员,如果不是,我想隐藏一些命令,例如 AppBarButton 和 menuflyout。当用户不是管理员时,如何在后面的代码中使用 visibility.collapsed 隐藏这些命令?

private async void Button_OK(object sender, TappedRoutedEventArgs e)
{
    Utilizador u = new Utilizador(null, TextBox1.Text, PasswordBox1.Password, null, null, false);
    if (u.GetByLoginAndPassword())
    {
        if (UtilizadorViewModel.Utilizador.Admin == false)
        {
            this.Frame.Navigate(typeof(BlankPage1), UtilizadorViewModel.Utilizador.Nome);
            //Visibility.Collapsed;
            MessageDialog a = new MessageDialog("Bem Vindo! ", u.Nome);
            await a.ShowAsync();
        } else
        {
            this.Frame.Navigate(typeof(BlankPage1), UtilizadorViewModel.Utilizador.Nome);
            //Visibility.Visible;
            MessageDialog a = new MessageDialog("Bem Vindo! ", u.Nome);
            await a.ShowAsync();
        }
    }
    else
    {
        MessageDialog md = new MessageDialog("Nome ou password errados");
        await md.ShowAsync();
    }

<Page.BottomAppBar>
        <CommandBar>
            <AppBarButton x:Name="addp" Label="Add" Tapped="AppBarButton_Tapped" Icon="Add"/>
        </CommandBar>
    </Page.BottomAppBar>

【问题讨论】:

    标签: c# xaml


    【解决方案1】:

    您可以隐藏整个应用程序栏或将其可见性设置为折叠:

    • ApplicationBar.IsVisible = false;
    • ApplicationBar.Visibility = Visibility.Collapsed;

    如果您需要访问单个按钮,您可以使用 2 种方法, 您可以完全删除按钮:

    • ApplicationBar.Buttons.RemoveAt(0);

    或使用该按钮的索引并将其设置为IsEnabled 属性:

    • ((ApplicationBarIconButton)ApplicationBar.Buttons[buttonIndex]).IsEnabled = false;

    If you need additional information - this answer explains it very well.

    Check out this one too.

    【讨论】:

      猜你喜欢
      • 2013-11-08
      • 2019-04-13
      • 2017-07-04
      • 2017-01-14
      • 2017-01-15
      • 2018-11-28
      • 2012-05-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多