简体   繁体   中英

Share xaml between UWP app pages

I have an app which has navigation bar at the bottom. I'd like to keep that part of the page static - it would be 'base' for all other pages. I could add the exact same part of the code to every xaml page, however, I feel like initializing navigation bar on each page is waste of resources and time.

To make it more clear, below is an image of Facebook app (iPhone), pretty much same UI on Windows 10. Red bordered part of the UI never changes no matter what page you move to. For those using Facebook app you know that when you slide left/right only content in the middle (without red border) changes and slide animation is applied only to that part of the page.

That is basically what I'd like to achieve. Static part of the code that will initialize only once, stay visible on all pages, and no animations or page transitions would apply to it while switching between pages. I've been reading documentation and have not found any helpful information on how to achieve that.

Facebook的

You can easily implement this by creating a page with the shared controls and a ContentControl object, which will be responsible of showing the actual page content.

The ContentControl represents a control with a single piece of content of any type; which means you can put, for example; a UserControl inside of it, even a Page .

That being said, keep in mind that by doing so; you will lose the Frame functionality and will need to handle many things on your own, such as the navigation stack and back button functionality.

I'll leave you this question on SO which can be of help in your case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM