是否可以在Silverlight Web应用程序和Windows Phone 7应用程序之间共享代码 [英] Is it possible to share code between a Silverlight web app and Windows Phone 7 app

查看:79
本文介绍了是否可以在Silverlight Web应用程序和Windows Phone 7应用程序之间共享代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Silverlight应用程序,我想几乎完全在Windows Phone 7上运行它.我创建了一个新的Windows Phone 7项目,当我引用Silverlight应用程序时,出现警告:添加对Silverlight项目的引用可能无法正常工作.您要继续吗?".

I have a simple Silverlight app that I want to run on Windows Phone 7 almost exactly as is. I've created a new Windows Phone 7 project and when I reference the Silverlight app I get a warning that says "Adding a reference to a Silverlight project might not work properly. Do you want to continue?".

如果我继续尝试并尝试运行,则WP7项目将永远不会启动,或者有时会出现"AG_E_PARSER_BAD_TYPE错误",它指向我使用Silverlight项目中的控件的xaml行.

If I continue and try to run anyway, the WP7 project never starts or sometimes I get "AG_E_PARSER_BAD_TYPE error" and it points to the line in the xaml I used a control from the Silverlight project .

这两个项目之间的代码大约有99%相同.还有什么方法可以重用代码,而不是我正在尝试的代码?或者我该如何使用它?

The code between these two projects is about 99% the same. Is there another way to reuse code then what I am trying? Or how can I get this to work?

推荐答案

实现此目标的典型方法是使用MVVM之类的模式,该模式将允许您定义通用模型和viewmodel层(也许在单独的项目中),定义引用该普通项目的其他视图层.

The typical way of achieving this is by using a pattern like MVVM which will allow you to define a common model and viewmodel layer (perhaps in a separate project) the defining a different view layer that references that common project.

您自己说的话,您只会共享大部分的代码,而不是全部,因此,至少在某些时候,您需要创建特定于设备/前端的逻辑和布局.

You said it yourself, you will only share MOST of the code, not all of it, so you will, at least at some time, need to create device/front-end specific logic and layout.

这篇关于是否可以在Silverlight Web应用程序和Windows Phone 7应用程序之间共享代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆