views:

26

answers:

1

Hi, 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

+1  A: 

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;
Stephan
Yes, that works, thanks very much.
Jan Kratochvil