在 UWP 应用中使用 WPF dll
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34477450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using WPF dll's in UWP app
提问by JamesNZ
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?
我正在编写一个 UWP 应用程序,但由于某种原因我无法引用PresentationFramework.dll. 它包含一些我想使用的 WPF 控件(特别是System.Windows.Controls.DataGrid,但它们在通用 Windows >> 参考管理器中的扩展下不可用。这是为什么,我该如何解决?
回答by Bart
TL;DR: You can't use WPF controls in UWP.
TL;DR:您不能在 UWP 中使用 WPF 控件。
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 postis a good entry point.
WPF 和 UWP 是两个完全不同的 API,它们具有不同的 .NET 框架。虽然 WPF 可以访问完整的 .NET Framework,但 UWP 的 API 更为有限。如果您想阅读有关不同平台和编译器的更多信息,这篇msdn 博客文章是一个很好的切入点。
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.
因此,您无法添加任何标准 dll 作为对 UWP 应用的引用。如果您想在 WPF 和 UWP 之间共享代码,则必须使用可移植类库,您可以在其中定位所需的平台。
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.
由于 WPF 和 UWP 的 XAML 命名空间也不同,因此您不会发现很多可移植控件。因此,对于 UWP 开发,您需要使用 UWP 控件(相当于它们的 WPF 对应控件)。额外提示:如果您正在寻找 3rd 方控件,您也可以查找“winrt”控件,因为 winrt 用于 Windows 8/8.1,但它是相同的技术。


