How to change the image on the ApplicationBar from C#?

前端 未结 3 1524
长情又很酷
长情又很酷 2021-01-21 14:31

I have a small C# project that has an ApplicationBar. But I have a small problem: I want 8 icons on the bar, and the ApplicationBar only supports 4. I came up with a solution (i

相关标签:
3条回答
  • 2021-01-21 14:49

    You can't refer to the application buttons by name. Try:

    ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Remove
    

    I would also suggest that you do not present two groups of 4 icons to the user. The limit is 4 for a reason. Any more than that requires a UI re-think. Perhaps divide the functionality over a few pages?

    0 讨论(0)
  • 2021-01-21 14:50

    The syntax above gave me a compile error. With some additional research, I got this to work for me:

    ApplicationBar.Buttons.Remove((ApplicationBarIconButton) ApplicationBar.Buttons[0]);
    
    0 讨论(0)
  • 2021-01-21 14:56

    I don't understand what you mean by changing it from "C#, not Silverlight". C# is a programming language and Silverlight is a framework. Nevertheless, the link you posted to explains exactly how you do it. The ApplicationBar is not a Silverlight control, it's part of the native OS. You can use the code in the link or do something like this:

    firstAppBarButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
    firstAppBarButton.Text = "New Text";
    firstAppBarButton.IconUri = new Uri("/appbarIcon.png",UriKind.Relative);
    

    You need to get the ApplicationBarIconButton via the index (0 for first one, 1 for second etc..) instead of by name.

    0 讨论(0)
提交回复
热议问题