简体   繁体   English

.NET Core 3 WPF 和路径

[英].NET Core 3 WPF and Paths

I'm playing with .NET Core 3 and its support for WPF on Visual Studio 2019. I've created a canvas and would like to draw a geometry from code.我正在使用 .NET Core 3 及其对 Visual Studio 2019 上的 WPF 的支持。我创建了一个画布并想从代码中绘制几何图形。 I'm initialliy attempting to do this by binding the Canvas' Path Data dependency property to a PathGeometry in my ViewModel, ie,我最初试图通过将画布的路径数据依赖属性绑定到我的 ViewModel 中的 PathGeometry 来实现这一点,即,

<Path Data="{Binding PathGeometry}"/>

and then setting the PathGeometry in my ViewModel, something like然后在我的 ViewModel 中设置 PathGeometry,类似于

    public class MyViewModel : ViewModelBase
    {   

        public PathCanvasViewModel()
        {   
            var arcSegment = new ArcSegment
            {
                // INVALID in .NET Core 3 lib
                Point = new System.Windows.Point()
            };

            var pathFigure = new PathFigure();
            pathFigure.Segments.Add(arcSegment);

            PathGeometry = new PathGeometry();
        }

        public PathGeometry PathGeometry { get; }
    }

However, the view model won't build due to System.Windows.Point not being available in the System.Windows namespace.但是,由于System.Windows.PointSystem.Windows命名空间中不可用,因此不会构建视图模型。 I presume this is because my view model is defined in a pure .NET Core 3 library - if I install the preview nuget package Microsoft.WindowsDesktop.App then I'll have access to Point in System.Windows and the application will build.我认为这是因为我的视图模型是在纯 .NET Core 3 库中定义的 - 如果我安装预览版 nuget 包Microsoft.WindowsDesktop.App那么我将可以访问System.Windows Point并且应用程序将构建。

Now I'm confused, as the docs for ArcSegment say it supports .NET Core 3.0 Preview 7 as do the docs for Point , and I'm running that version of .NET Core.现在我很困惑,因为ArcSegment的文档说它支持.NET Core 3.0 Preview 7Point的文档也是如此,我正在运行该版本的 .NET Core。 So why can I build my .NET Core 3 view model library defining an ArcSegment , but as soon as I try to specify a Point for that ArcSegment I get a build failure?那么为什么我可以构建定义ArcSegment .NET Core 3 视图模型库,但是一旦我尝试为该ArcSegment指定一个Point ,我就会构建失败?

To save people a click here was the resolution from GitHub issue为了拯救人们,点击这里是 GitHub 问题的解决方案

@jdbriaris, the problems with documentation notwithstanding (thanks for bringing this to our attention - its greatly appreciated!), you will not be able to use WPF types without referencing Microsoft.WindowsDesktop.App. @jdbriaris,尽管文档存在问题(感谢您提请我们注意这一点 - 非常感谢!),如果不引用 Microsoft.WindowsDesktop.App,您将无法使用 WPF 类型。 This includes System.Windows.Point, as well as System.Windows.Media.ArcSegment.这包括 System.Windows.Point 以及 System.Windows.Media.ArcSegment。

There are some exceptions to this generality - eg, some types in System.IO.Packaging namespace - that will be available in Microsoft.NetCore.App, and will also continue to be available in Microsoft.WindowsDesktop.App through type-forwards in WindowsBase.dll (as they used to in .NET Framework).这种通用性有一些例外 - 例如,System.IO.Packaging 命名空间中的某些类型 - 它们将在 Microsoft.NetCore.App 中可用,并且还将通过 WindowsBase 中的类型转发继续在 Microsoft.WindowsDesktop.App 中可用.dll(就像他们在 .NET Framework 中使用的那样)。

The general idea is that WPF and WinForms reside in Microsoft.WindowsDesktop.App.总体思路是 WPF 和 WinForms 驻留在 Microsoft.WindowsDesktop.App 中。

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

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