In my project I have a library shared between WP7 and WP8 clients. The library contains views, view models and other interesting data.
I also want to use the latest version of Windows Phone Toolkit.
The problem that I run into is that while my xaml code is compatible, I get a runtime error, because LongListSelector exists in different assemblies in Windows Phone Toolkit for wp7 and in framework code for WP8.
in wp7:
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
in wp8:
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
How can I solve this conundrum without needing to duplicate my xamls for both platforms?
After all this is the solution I decided to implement:
I decided that the library that contains all views for WP7 an WP8 was not the right place for views that are in fact different in respective platforms. So I created two copies of problematic views and placed them in their respective application projects for WP7 and WP8.
This created some duplication in xaml - fortunately for me my xamls were not very complex - just a handful of controls, styled. So I created a style dictionary for each page and placed in alongside the page in the WP7 project.
I linked the dictionary file into the WP8 project. I did the same for the code behind file.
In my xaml files I linked the local dictionary file with styles used on those pages:
With this solution I achieved minimal code duplication, with all styles still in one place, and the only differing code (XAML) placed where it really belongs.
The final folder tree looks something like this:
Solution
|-- Common Library
| |-- Views
| |-- Page1
+-- WP7
|-- Views
|-- Page1
|-- Page1.xaml (Windows 7 specific markup)
|-- Page1.xaml.cs (code behind file)
|-- Page1.styles.xaml (common styles shared between wp7 and wp8 apps)
+-- WP8
|-- Views
|-- Page1
|-- Page1.xaml (Windows 8 specific markup)
|-- ->Page1.xaml.cs (linked from the WP7 project)
|-- ->Page1.styles.xaml (linked from the WP7 project)
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.