2

I have been attempting to set the applicationbar on my MainPage in the code behind based on a slider bar that the user may control at will. I have a lot of information in my applicationbar so I created it in xaml, except for the opacity which should change depending on the values of the slider. I am unsure though of how to access the MainPage applicationbar opacity from the codebehind?

Matthew
  • 3,976
  • 15
  • 66
  • 130

2 Answers2

4

Try this:

 ApplicationBar = new ApplicationBar();
 ApplicationBar.Opacity=0.5;
 ApplicationBar.IsMenuEnabled = true;
 ApplicationBarIconButton button1 = new ApplicationBarIconButton(new Uri("/Images/appbar.feature.search.rest.png", UriKind.Relative));
 button1.Text = "Search";
 ApplicationBar.Buttons.Add(button1);
 ApplicationBarMenuItem menuItem1 = new ApplicationBarMenuItem("MenuItem 1");
 ApplicationBar.MenuItems.Add(menuItem1);
coder
  • 13,002
  • 31
  • 112
  • 214
  • Just the `ApplicationBar.Opacity=0.5;` is needed, since he's creating the ApplicationBar from the XAML. – Kevin Gosse May 02 '12 at 08:39
  • Yes.Indeed not to make the OP repeat or reask again on the same issue I mentioned everything and specifically OP asked that he needs to change from his code-behind. – coder May 02 '12 at 08:41
  • @coder, thanks for your quick answer, although creating a new instance of the applicationbar was not working for me, although I did finally figure out a solution that I have answered below. – Matthew May 02 '12 at 19:37
1

To change the opacity value of a currently existing ApplicationBar, use the following

(ApplicationBar as ApplicationBar).Opacity = num;

where num is your opacity of preference!

Matthew
  • 3,976
  • 15
  • 66
  • 130