简体   繁体   中英

.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. I'm initialliy attempting to do this by binding the Canvas' Path Data dependency property to a PathGeometry in my ViewModel, ie,

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

and then setting the PathGeometry in my ViewModel, something like

    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. 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.

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. 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?

To save people a click here was the resolution from GitHub issue

@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. This includes System.Windows.Point, as well as 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).

The general idea is that WPF and WinForms reside in Microsoft.WindowsDesktop.App.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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