Change BackGround color in full screen?

Developer
Jun 17, 2009 at 8:10 AM
Edited Jun 17, 2009 at 8:14 AM

Due to the layout and color scheme of my site, I am using a theme where the background color is set to white.  If the user goes to full screen, I'd prefer the background go to black, and then back to my theme (or config default) color (in this case, back to white).

I have the first part working great.  Adding the following lines to ToggleFullScreenOn() in Navigation.cs does the trick of forcing the background to black when the user enters full screen:

            Page page = App.Current.RootVisual as Page;
            page.SlideShowRoot.Background = new SolidColorBrush(Colors.Black);

However, I'm having trouble getting the background back to white when the user exits full screen mode.  Adding code like the following to ToggleFullScreen() (called by KeyboardSupport) and to ToggleFullScreenOff() doesn't do anything.

            Page page = App.Current.RootVisual as Page;
            page.SlideShowRoot.Background = new SolidColorBrush(Colors.White);

Once I get it working, I won't hard code the return color back to white (I'll reference the config setting), but for testing purposes I'm just trying to hard code white and can't get even that to work.

Any ideas?

Developer
Jun 17, 2009 at 9:20 AM

I got it working.

The problem above was that when in full screen mode, if the user presses esc to exit, you can't trap that key press.  This is done for security reasons:

http://msdn.microsoft.com/en-us/library/cc189023(VS.95).aspx

This means that the KeyboardSupport listener that I thought was going to get called never got called for that esc.  If the user pressed the navigation button that returns to regular mode, that was trapped and could be handled in the ToggleFullScreenOff method in Navigation.

OK, so that didn't work...what did?

In Page.xaml.cs, I added the following to the WireEventHandlers method:

            App.Current.Host.Content.FullScreenChanged += delegate
            {
                Navigation.ToggleFullScreenBackground();
            };

Then, in Navigation.cs, I added the following method:

        /// <summary>
        /// Toggles background color based on full screen mode.
        /// </summary>
        public static void ToggleFullScreenBackground()
        {
            Page page = App.Current.RootVisual as Page;
            page.SlideShowRoot.Background = new SolidColorBrush(App.Current.Host.Content.IsFullScreen ? Colors.Black : App.Current.Host.Background);
        }

And eureka, the background color alternates back and forth as desired, regardless of how the user switches (using navigation buttons or keyboard shortcuts)