在 UWP 应用中使用 WPF dll [英] Using WPF dll's in UWP app

查看:16
本文介绍了在 UWP 应用中使用 WPF dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 UWP 应用程序,但由于某种原因我无法引用 PresentationFramework.dll.它包含一些我想使用的 WPF 控件(特别是 System.Windows.Controls.DataGrid,但它们在通用 Windows >> 参考管理器中的扩展下不可用.这是为什么,以及如何我可以修吗?

解决方案

TL;DR:你不能在 UWP 中使用 WPF 控件.

WPF 和 UWP 是两个完全不同的 API,具有不同的 .NET 框架.虽然 WPF 可以访问完整的 .NET Framework,但 UWP 的 API 更为有限.如果您想阅读有关不同平台和编译器的更多信息,请访问

因此,您无法添加任何标准 dll 作为对 UWP 应用的引用.如果要在 WPF 和 UWP 之间共享代码,则必须使用

由于 WPF 和 UWP 的 XAML 命名空间也不同,因此您不会发现很多可移植控件.因此,对于 UWP 开发,您需要使用 UWP 控件(相当于它们的 WPF 对应控件).额外提示:如果您正在寻找 3rd 方控件,您也可以查找winrt"控件,因为 winrt 用于 Windows 8/8.1,但它是相同的技术.

I'm writing a UWP app, and for some reason I'm unable to reference PresentationFramework.dll. It contains some WPF controls I want to use (specifically, System.Windows.Controls.DataGrid, but they aren't available under Universal Windows >> Extensions in the reference manager. Why is this, and how can I fix it?

解决方案

TL;DR: You can't use WPF controls in UWP.

WPF and UWP are two totally different APIs with a different .NET framework. While WPF has access to the full .NET Framework, UWP has a much more limited API. If you want to read more on the different platforms and compilers, this msdn blog post is a good entry point.

You are thus unable to add any standard dlls as a reference to an UWP app. If you want to share code between WPF and UWP, you'll have to use a Portable Class Library, in which you target the platforms you need.

And as the XAML namespaces for WPF and UWP are different as well, you won't find many portable controls. So for UWP development you'll need to use UWP controls (equivalent to their WPF counterparts). Bonus tip: if you're looking for 3rd party controls, you can also look for 'winrt' controls as winrt was used for Windows 8/8.1, but it's the same technology.

这篇关于在 UWP 应用中使用 WPF dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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