Глобальная панель приложений, добавьте другие кнопки на эту панель приложений для определенной страницы.

Я добавляю панель приложений с 3 кнопками в App.xaml.cs, чтобы разместить ее на каждой странице, но у меня есть страница, на которую я хотел бы добавить еще одну кнопку.

Что я делаю, так это получаю панель приложений с тремя кнопками по умолчанию из App.xaml.cs, а затем добавляю другую кнопку. Проблема в том, что когда он добавлен и когда я меняю страницу, кнопка, которую я добавил, остается видимой... Таким образом, это проблема со ссылкой на объект, потому что каждая страница ссылается на одну и ту же панель приложений.

Интересно, можно ли скопировать эту панель приложений только для страницы с 4 кнопками... (Icloneable? но я не знаю как :/) Как вы думаете? Я также должен упомянуть, что некоторые кнопки используют навигацию для перехода на другую страницу.

Вот мой код:

App.xaml.cs

private ApplicationBar _appBar;
public ApplicationBar AppBar { get { return _appBar; } } //property called in other page

//Method called in the constructor
private void BuildLocalizedApplicationBar()
    {
        // Set the page's ApplicationBar to a new instance of ApplicationBar.
        _appBar = new ApplicationBar();

        // Create a new button and set the text value to the localized string from AppResources.
        var appBarButtonScan = new ApplicationBarIconButton(new Uri("/Assets/AppBar/White/appbar.qr.png", UriKind.Relative));
        appBarButtonScan.Click += AppBarButtonScanOnClick;
        appBarButtonScan.Text = AppResources.Scan;

        var appBarButtonSearch = new ApplicationBarIconButton(new Uri("/Assets/AppBar/White/appbar.search.png", UriKind.Relative));
        appBarButtonSearch.Click += AppBarButtonSearchOnClick;
        appBarButtonSearch.Text = AppResources.Search;

        var appBarButtonFacebook = new ApplicationBarIconButton(new Uri("/Assets/AppBar/White/appbar.facebook.png", UriKind.Relative));
        appBarButtonFacebook.Click += AppBarButtonFacebookOnClick;
        appBarButtonFacebook.Text = AppResources.MyAccount;

        _appBar.Buttons.Add(appBarButtonScan);
        _appBar.Buttons.Add(appBarButtonSearch);
        _appBar.Buttons.Add(appBarButtonFacebook);

        // Create a new menu item with the localized string from AppResources.
        ApplicationBarMenuItem appBarMenuSettings = new ApplicationBarMenuItem(AppResources.SettingsTitle);
        _appBar.MenuItems.Add(appBarMenuSettings);
    }

На странице, где я хотел бы иметь одну кнопку в дополнение:

private void BuildLocalizedApplicationBar()
    {
        App _app = Application.Current as App; //in my page, it's an attribute that I initialize in my constructor.
        ApplicationBar = _app.AppBar; //get the appbar with 3 buttons from App.xaml.cs

        // Create new buttons and set the text value to the localized string from AppResources.
        ApplicationBarIconButton appBarButtonTagPlace = new ApplicationBarIconButton(new Uri("/Assets/AppBar/White/appbar.heart.outline.png", UriKind.Relative));
        appBarButtonTagPlace.Text = AppResources.TagThisPlaceTitle;
        appBarButtonTagPlace.Click += AppBarButtonTagPlaceOnClick;


        ApplicationBar.Buttons.Add(appBarButtonTagPlace);
    }

заранее спасибо


person Volkan    schedule 23.04.2013    source источник


Ответы (1)


Вы можете удалить кнопку при выходе со страницы, на которой есть дополнительная кнопка.

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
    ApplicationBar.Buttons.Remove(appBarButtonTagPlace);
    base.OnNavigatedFrom(e);
}
person keyboardP    schedule 23.04.2013