开发者

A better way to show different wpf pages in mainWindow?

开发者 https://www.devze.com 2023-01-30 17:16 出处:网络
I have several Wpf pages in my project, these pages have different forms and ui control indide theme. The image below shows the mainWindow and there are two button.

I have several Wpf pages in my project, these pages have different forms and ui control indide theme. The image below shows the mainWindow and there are two button. I want to show a specific page when I click on + or Edit button using the Frame control which is highlighted.

apparenatly this woks:

Page1 me = new Page1(); 
mainFrame.Content = me; 

But开发者_运维知识库 it has an IE navigation sound and a toolbar appears after going to page2. any better way to show diffrent pages and not using a frame?

A better way to show different wpf pages in mainWindow?


You may want to convert the Page into a UserControl. You can then put that control inside some other container, such as a Grid. You'll have to manually swap out the pages in the container when navigating, but it looks like you're doing that anyway.


The purpose of the Frame control is to allow navigation. If you don't want navigation, then don't use Frame. You can turn off the navigation toolbar, but that won't actually disable navigation - there are mouse buttons and keyboard shortcuts for navigating back.

If you just want to host a UI element without navigation, use something simpler, like a Border element - put the content in its Child property. You can change the Child as many times as you like at runtime.


I was able to set the frame control's NavigationUIVisibility to Hidden. This solved the problem for me. I am using Visual Studio 2010 though so it might not be applicable to older VS versions.


Ian Griffiths, what you suggest increases the workload on the developer substantially. And you are stepping outside of the underlying paradigm of XAML.

In my case I'm developing a game application and have chosen WPF as the UI platform as much as possible. For me that means a intro screen, character select, etc. The purpose of Pages is to encapsulate the navigational need of such an application.

I suspect your downvote is due to your statement "If you don't want navigation...". Upon re-reading the original posters question I see he does want navigation, he just wants it on his own terms. I would have voted you down too. YotaXP's solution neglects the issues with using a User Control, particularly if it may contain other User Controls. It looks like Chris Calvert came up with an actual solution to the poster's issue within the parameters of the problem.

I would be curios if I could override the navigation hotkeys and such within the existing paragimn but that's properly in its own thread.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号