未设置 AppBarButton 可见性 [英] AppBarButton Visibility is not set

查看:38
本文介绍了未设置 AppBarButton 可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码隐藏中设置 AppBarButton 可见性时遇到问题.

I have troubles with setting AppBarButton visibility in codebehinde.

这是我的 XAML:

<Page.BottomAppBar>
    <AppBar Background="{ThemeResource AppBarBackgroundThemeBrush}">
        <StackPanel Orientation="Horizontal">
            <AppBarButton Icon="Save" Label="Uložit" x:Name="AppBarButtonSave" Click="AppBarButtonSave_OnClick" />
            <AppBarButton Icon="Mail" Label="Odeslat" x:Name="AppBarButtonMail" Visibility="Collapsed" />
            <AppBarButton Icon="Clear" Label="Zrušit" x:Name="AppBarButtonCancel" Click="AppBarButtonCancel_OnClick" />
            <AppBarButton Icon="Help" Label="Info" x:Name="AppBarButtonAbout" Click="AppBarButtonAbout_Click" />
        </StackPanel>
    </AppBar>
</Page.BottomAppBar>

还有我的 C#:

public MainPage()
    {   
        this.InitializeComponent();
        this.LoadLastResult();
    }

private void LoadLastResult()
{
    var savedItems = (List<AresDb>)this.lvwSaved.ItemsSource;

    if (savedItems.Any(o => o.Ico == ares.Info.Ico))
    {
        this.AppBarButtonSave.Visibility = Visibility.Collapsed;
    }
}

即使代码被触发,按钮仍然可见.但是,如果我尝试在某些 Click 操作中设置可见性,例如.单击按钮时,可见性设置正确.

Even if the code is triggered, the button is still visible. But if I try to set visibility in some Click action, eg. when button is clicked, the visibility is set properly.

有没有人知道为什么它在点击操作中效果很好,但在应用启动时不行?

Have anybody idea, why it works well in click action, but not when App start?

推荐答案

毕竟,我明白了.Pivot OnSelectionChange 方法存在问题.因为当应用程序启动时,这个方法是在所有其他方法之后调用的.所以它将我的 AppBarButton 可见性设置回可见.但是当你触发点击动作时,不会触发这个方法.

After all, i figure it. There is problem with Pivot OnSelectionChange method. Because when app launch, this method is called after all others. So it set my AppBarButton visibility back to Visible. But when you trigger the click action, this method is not triggered.

这篇关于未设置 AppBarButton 可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆