user1428798
user1428798

Reputation: 1546

set visibility of ApplicationBarIconButton to false in wp7

I have an application bar in my windows phone application

  <phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar>
        <shell:ApplicationBarIconButton x:Name="Refresh" IconUri="Images/appbar.sync.rest.png" Text="Actualiser" Click="ApplicationBarIconButton_Click" />
        <shell:ApplicationBarIconButton x:Name="Favorite"  IconUri="Images/appbar.favs.addto.rest.png" Text="Favorite" Click="ApplicationBarIconButton_Click_1" />
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

I nedd to set the visibility of <shell:ApplicationBarIconButton x:Name="Favorite" IconUri="Images/appbar.favs.addto.rest.png" Text="Favorite" Click="ApplicationBarIconButton_Click_1" /> to false when i click

How can do this??

Best regards

Upvotes: 0

Views: 1268

Answers (2)

Paras Wadehra
Paras Wadehra

Reputation: 478

What you need to do is have 2 different AppBars in your application - the first with the 2 ApplicationBarIconButtons (Refresh and Favorite) and the second with only the Refresh ApplicationBarIconButton.

In your EventHandler for ApplicationBarIconButton_Click_1, you can change the AppBar that is currently being displayed to the user.

Something like this works...

ApplicationBar appBar1 = new ApplicationBar();
ApplicationBarIconButton refreshIcon = new ApplicationBarIconButton();
refreshIcon.text = "Refresh";
refreshIcon.Click += new EventHandler(Refresh_Click);
appBar1.add(refreshIcon);

ApplicationBarIconButton favIcon = new ApplicationBarIconButton();
favIcon.text = "Refresh";
favIcon.Click += new EventHandler(Fav_Click);
appBar1.add(favIcon);

ApplicationBar appBar2 = new ApplicationBar();
ApplicationBarIconButton refreshIcon2 = new ApplicationBarIconButton();
refreshIcon2.text = "Refresh";
refreshIcon2.Click += new EventHandler(Refresh_Click);
appBar2.add(refreshIcon2);

ApplicationBar = appBar1; // Assign the AppBar with both buttons as the default.

Then in the EventHandler for Fav_Click, write

ApplicationBar = appBar2; // This will make the AppBar with only "Refresh" button visible giving the impression that the Favorite button has been made invisible.

Upvotes: 0

Milan Aggarwal
Milan Aggarwal

Reputation: 5104

You cannot set visibility of individual buttons in the app bar to collapsed. But you can enable/disable them by using the IsEnabled property or remove them dynamically from your code behind ApplicationBar.Buttons.Remove(object) and pass the button object which you receive on click event. I guess it should work.

Upvotes: 3

Related Questions