In Part 4 we finished with an MVVM app, running on both Windows 8 and Windows Phone. In this post I’m going to explore the idea of using the same XAML.
Is this a good idea?
The very short answer is probably “NO!“. The problem is that in anything but the most trivial of applications, the XAML will need to differ. In this application, it probably doesn’t matter, but then, it wouldn’t kill anyone to maintain two sets of very trivial XAML either.
My approach to this, and to the above question is to create a custom user control, and then use that in both applications. The good thing about this is that it does make sense to share user controls (to me anyway).
We’ll create a View directory in the shared project, and add the UserControl there:
It should look like this:
You'll be familiar with this XAML by now. Nothing had changed, it's the same. In the Phone app, we'll replace the whole XAML with the following:
And the Windows 8 XAML with this:
Other than the theme, they are the same. You could obviously just have MainPage in the shared project, but personally, I don't believe that is extensible; if you do so, you run the risk of ending up with an overly complex XAML file trying to cater for each separate project type.
Just a short post this time. In the next post on this, I'm going to add the missing functionality. This should be far easier now that the whole application is basically inside the shared project.