gpt4 book ai didi

c# - 进入全屏模式时更改页面

转载 作者:太空宇宙 更新时间:2023-11-03 14:27:55 25 4
gpt4 key购买 nike

我的问题很简单:当用户在 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;
}

执行上面的代码时,应用进入全屏模式,但页面没有改变,只是调整了大小。谁能告诉我该代码有什么问题?谢谢

最佳答案

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;

关于c# - 进入全屏模式时更改页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3405474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com