当从WPF应用程序引用的Silverlight类库错误 [英] Errors when referencing Silverlight class library from WPF application

查看:161
本文介绍了当从WPF应用程序引用的Silverlight类库错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF应用程序和Silverlight应用程序。它们都用于显示地图和共享一些相同的功能。

I have a WPF application and a Silverlight application. They are both used to display a map and share some of the same functionality.

我创建一个Silverlight类库项目,以保持干燥。我从两个Silverlight和WPF引用此。这里面有些是在两个项目中非常有用的工具方法。例如,我有这样的方法:

I have created a Silverlight class library project in order to stay DRY. I'm referencing this from both Silverlight and WPF. It contains some utility methods that are useful in both projects. For example, I have this method:

public static void CenterText(TextBlock name, Polygon poly)

Silverlight项目与此没有任何问题。不过,我调用这个时候出现以下错误从我的WPF应用程序:

The silverlight project has no problem with this. However, I get the following error when calling this from my WPF application:

类型System.Windows.Shapes.Polygon'中未被引用的组件被定义。您必须添加一个引用程序集System.Windows,版本= 2.0.5.0,文化=中性公钥= 7cec85d7bea7798e

The type 'System.Windows.Shapes.Polygon' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'

不过,我有这条线在文件的顶部:

However, I have this line at the top of the file:

using System.Windows.Shapes;

所以WPF可以看到Polygon类完全正常。 我的猜测是,Silverlight的类库使用一个版本,这是不符合的WPF项目正在使用的版本不兼容的框架。

so WPF can see the Polygon class perfectly fine. My guess is that the silverlight class library uses a version of the framework which is not compatible with the version that the WPF project is using.

所以,问题是,我是停留在我的WPF应用程序重写如出一辙code或者是有一些方法可以让我在两者之间共享?

So the question is, am I stuck rewriting exactly the same code in my WPF application or is there some way I can share between the two?

谢谢!

推荐答案

你是对的,Silverlight使用该框架的一个完全独立的版本。这是多少,比事件更小的.NET客户端运行时。

You are right, Silverlight uses a completely separate version of the framework. It's much, much smaller than event the .NET client runtime.

这意味着你不能混用WPF和Silverlight组件在同一应用程序。

This means you can't mix WPF and Silverlight assemblies in the same application.

这篇关于当从WPF应用程序引用的Silverlight类库错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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