Tutorial :Change Page when entering fullscreen mode



Question:

my problem is quite simple: when user changes selection in a ListBox, I need my app to go to fullscreen mode, but I need to change the displayed page. I use Silverlight 4

 private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)      {              PresentationPage currentPresentationPage = new PresentationPage();                App.Current.RootVisual = currentPresentationPage;              App.Current.Host.Content.IsFullScreen = true;      }  

When the code above is executed, the app goes to fullscreen, but the Page does not change, it only resizes. Can anybody tell me what's wrong with that code? Thanks


Solution:1

You can't change Application.RootVisual after it is assigned. What you need to do is include a panel that you can change it's content and make that panel your RootVisual.

 private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)   {          PresentationPage currentPresentationPage = new PresentationPage();            (App.Current.RootVisual as Panel).Children.Clear();          (App.Current.RootVisual as Panel).Children.Add(currentPresentationPage);          App.Current.Host.Content.IsFullScreen = true;   }  

Then in your App's Startup event do something like so.

Panel grid = new Grid();  grid.Children.Add(new MainPage());  App.Current.RootVisual = grid;  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »