简体   繁体   中英

Where should XAML pages live in a universal app?

Universal apps allow sharing of common assets in the Shared Project, including XAML pages. However the Hub App (Universal Apps) project template creates two distinct MainPage.xaml files in each platform-specific project.

Is there any reason for this? Am I going to regret putting all of my XAML files in the Shared Project?

If one XAML file can be used for both platforms then put it into the shared project. If the views differ too much between the platforms or the UI performance is bad when sharing XAML code then you should create separate XAML files and put them in both projects.

Putting the XAML file into the shared project is the same as having the same file in both projects. Adding files to the shared project is the same as linking files into a project - just more convenient. ( Read this article about file linking and PCL )

I recommend to start with everything UI (eg XAML, converters, ...) in the shared project and view models and logic in an external PCL library (with W8 and WP8.1 targets).

If a view/XAML file is different in W8 or WP then you can copy the XAML for this particular view into both platform specific projects.

More detailed information: http://blog.galasoft.ch/posts/2014/04/about-windows-phone-8-1-and-universal-apps/

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