AppBarButton Visibility is not set

≡放荡痞女 提交于 2019-12-25 08:58:53

问题


I have troubles with setting AppBarButton visibility in codebehinde.

There is my 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>

And my 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;
    }
}

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?


回答1:


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.



来源:https://stackoverflow.com/questions/31904996/appbarbutton-visibility-is-not-set

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!