Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP7 ApplicationBarIcon Visibility

Appreciate that the WP7 ApplicationBarIcon is not standard control as such.

I need to be able to hide this programatically (I need to hide rather than disable)

1/ is there any other way I can do this other than adding/removing the icon

2/ assuming that I have to add and remove it, how do I associate an event to the control that I am adding?

  • thanks
like image 435
Peter Avatar asked Dec 06 '25 18:12

Peter


1 Answers

The following shows: creating an appbar in code; adding a button to it (including a "click" event handler); and removing the specific button.

    this.ApplicationBar = new ApplicationBar();

    var newButton = new ApplicationBarIconButton();
    newButton.IconUri = new Uri("/images/remove.png", UriKind.Relative);
    newButton.Text = "remove";
    newButton.Click += RemoveAppBarButton;

    this.ApplicationBar.Buttons.Add(newButton);


void RemoveAppBarButton(object sender, EventArgs e)
{
    for (var i = 0; i < this.ApplicationBar.Buttons.Count; i++)
    {
        var button = this.ApplicationBar.Buttons[i] as ApplicationBarIconButton;

        if (button != null)
        {
            if (button.Text == "remove")
            {
                this.ApplicationBar.Buttons.RemoveAt(i);
                break;
            }
        }
    }
}

The important thing to note is that you can't refer to buttons (or menu items) by name.

like image 182
Matt Lacey Avatar answered Dec 10 '25 03:12

Matt Lacey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!