2010-08-04 37 views
2

我的问题很简单:当用户更改ListBox中的选择时,我需要我的应用程序转到全屏模式,但我需要更改显示的页面。我使用Silverlight 4当进入全屏模式时更改页面

private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
      PresentationPage currentPresentationPage = new PresentationPage(); 

      App.Current.RootVisual = currentPresentationPage; 
      App.Current.Host.Content.IsFullScreen = true; 
    } 

在执行上面的代码,应用程序进入到全屏,但是页面并没有改变,它只是调整大小。有人可以告诉我该代码有什么问题吗?谢谢

回答

1

分配后,您不能更改Application.RootVisual。你需要做的是包括一个面板,你可以改变它的内容,并使该面板为你的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; 
} 

然后在您的应用程序的Startup事件中做类似的事情。

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

是的,这是有效的,非常感谢。 – 2010-08-06 08:47:14

相关问题