Windows 8.1 Universal Apps (Part 4: XAML)


As mentioned in the previous post in this series, by default App.xaml will be in the Shared folder, but you’ll have a unique MainPage.xaml for Windows and Windows Phone. You may have wondered that, as you can clearly share App.xaml between projects, if you can share other XAML. The answer is yes: you can share all XAML between your projects. WinRT on the phone contains all of the UI elements you have in WinRT in Windows 8, and we use the same controls in both types of applications.

If you’re going to make a fairly simple application with a simple UI, then you can actually go as far as deleting MainPage.xaml from both the Windows and Windows Phone projects and creating one in the Shared project instead. I’ve done this in Proverbinatus, as the in-app experience is simply seeing a quote in the middle of the page.

I wouldn’t recommend sharing XAML in more advanced apps, though. Particularly when you take into account that Windows 8 has snapping, while apps on Windows Phone are always full screen.

There is also no functionality similar to #IF WINDOWS_PHONE_APP to manipulate your XAML, so if you share your XAML, it will be identical.

If you do share files, the XAML designer in Visual Studio lets you swap between seeing what the XAML would look like on Windows or on Windows Phone. The default view is the current default project, but you can change it via the dropdown box highlighted in red in the following pictures.

Windows XAML View Windows Phone XAML View