问题
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