0

I am working on windows phone 8 app. I have two pages one has one applicationbar and second has three applicationbars which hide and unhide according to the situation. Everything was right unless i was implement the localization. I followed the following link and applied the localization in ApplicationBar within a page and its running. But everything fails when i applied same way localization into second page which has more than one applicationBar. no any applicationbar is visible.

my code according to this link click here to see link

private void myfucntion()
{
     ApplicationBar = new ApplicationBar();
     ApplicationBarIconButton btnSortGridView = new ApplicationBarIconButton(new Uri("Images/grid.png", UriKind.Relative));
     btnSortGridView.Text = AppResources.library_gridview;
     ApplicationBar.Buttons.Add(btnSortGridView);
     btnSortGridView.Click += btnSortGridView_Click;
     ApplicationBarIconButton btnSortListView = new ApplicationBarIconButton(new Uri("/Images/list.png", UriKind.Relative));
     btnSortListView.Text = AppResources.library_listview;
     btnSortListView.Click += btnSortListView_Click;
     ApplicationBar.Buttons.Add(btnSortListView);
}

you can see above ApplicationBar is the object of ApplicationBar(); when i press F12 (see definition) it redirect to me PhoneApplicationPage[from metadata] and following property was assigned with the same name

public IApplicationBar ApplicationBar { get; set; }

so want to say if i have a single ApplicationBar having localizatino than it above approach will work but if i have the more than one ApplicationBar than this Approach will not be work. Please help me your valuable suggession. Thanks in advance.

Ashish-BeJovial
  • 1,829
  • 3
  • 38
  • 62

1 Answers1

0

You can accomplish creating a second ApplicationBar by creating a new instance to a new variable. Curerntly your code is setting the page instance of the ApplicationBar (as seen by your go to definition). In your code, assign the new instance to the variable 'secondBar'

private ApplicationBar CreateSecondBar()
{
    ApplicationBar secondBar = new ApplicationBar();
    ApplicationBarIconButton btnSortGridView = new ApplicationBarIconButton(new Uri("Images/grid.png", UriKind.Relative));
    btnSortGridView.Text = AppResources.library_gridview;
    btnSortGridView.Click += btnSortGridView_Click;
    secondBar.Buttons.Add(btnSortGridView);

    ApplicationBarIconButton btnSortListView = new ApplicationBarIconButton(new Uri("/Images/list.png", UriKind.Relative));
    btnSortListView.Text = AppResources.library_listview;
    btnSortListView.Click += btnSortListView_Click;
    secondBar.Buttons.Add(btnSortListView);

    return secondBar;
}

Then when you want to change our the ApplicationBar for the page itself, you call the method and set from there.

var secondBar = CreateSecondBar();
// maybe you store this in a member variable "_secondBar" to be used whenever you need it

// using the this keyword to distinguish between the property, and the class
this.ApplicationBar = secondBar;
Shawn Kendrot
  • 12,425
  • 1
  • 25
  • 41
  • You are right, in my scenario requirement was different so what i am doing i am setting visibility true and false and calling my all appbars on diff-2 events. – Ashish-BeJovial Mar 03 '14 at 07:33