简体   繁体   English

在WP7和WP8之间共享使用LongListSelector的屏幕

[英]Screens using LongListSelector shared between WP7 and WP8

In my project I have a library shared between WP7 and WP8 clients. 在我的项目中,我在WP7和WP8客户端之间共享了一个库。 The library contains views, view models and other interesting data. 该库包含视图,视图模型和其他有趣的数据。

I also want to use the latest version of Windows Phone Toolkit. 我还想使用最新版本的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. 我遇到的问题是,虽然我的xaml代码是兼容的,但我收到运行时错误,因为LongListSelector存在于Windows Phone Toolkit for wp7和WP8框架代码中的不同程序集中。

in wp7: 在wp7中:

xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

in wp8: 在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? 如何在不需要为两个平台复制我的xamls的情况下解决这个难题?

After all this is the solution I decided to implement: 毕竟这是我决定实施的解决方案:

  1. 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. 我决定包含WP7和WP8的所有视图的库不适合在各自平台上实际上不同的视图。 So I created two copies of problematic views and placed them in their respective application projects for WP7 and WP8. 因此,我创建了两个有问题的视图副本,并将它们放在各自的WP7和WP8应用程序项目中。

  2. This created some duplication in xaml - fortunately for me my xamls were not very complex - just a handful of controls, styled. 这在xaml中创建了一些重复 - 幸运的是,我的xamls不是很复杂 - 只是少数控件,风格。 So I created a style dictionary for each page and placed in alongside the page in the WP7 project. 所以我为每个页面创建了一个样式字典,并放在WP7项目的页面旁边。

  3. I linked the dictionary file into the WP8 project. 我将字典文件链接到WP8项目中。 I did the same for the code behind file. 我为后面的代码做了同样的事情。

  4. In my xaml files I linked the local dictionary file with styles used on those pages: 在我的xaml文件中,我将本地字典文件与这些页面上使用的样式相关联:

  5. 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. 通过这个解决方案,我实现了最少的代码重复,所有样式仍然在一个地方,并且唯一不同的代码(XAML)放置在它真正属于的地方。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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