0

コード ビハインドでの AppBarButton の可視性の設定に問題があります。

私の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;
    }
}

コードがトリガーされても、ボタンは引き続き表示されます。しかし、いくつかのクリックアクションで可視性を設定しようとすると、たとえば. ボタンをクリックすると、可視性が適切に設定されます。

クリックアクションではうまく機能するのに、アプリの起動時には機能しない理由を誰か知っていますか?

4

1 に答える 1