I am working on a WinUI3 project, in the dependencies my frameworks are stated as Microsoft.NETCore.App
and Microsoft.Windows.SDK.Net.Ref
. I need a class to represent a rectangular geometry. I have found an already defined class: .windows.rect?view=windowsdesktop-9.0
It seems this class is within WindowsBase
assembly that I have within my project under `Microsoft.NETCore.App framework, but I don't know how to reference it ,namespaces
Online it is listed under Windows Desktop 9 (which means Windows Presentation Foundation?), anyway I cannot reference this class from within my project.
Can however reference Windows.Foundation.Rect
.foundation.rect?view=winrt-26100
but it misses much of the functionality I need such as IntersectsWith(Rect)
, Offset
, etc...
Also can reference System.Drawing.Rectangle
.drawing.rectangle?view=net-8.0 which is listed under .NET but in the description says is designed for Windows Forms which I heard is to be discontinued
So first, I don't understand why I can access one but not the other, also what should I do? To be honest I spent so much time trying to make sense of it all that perhaps it would be better to implement everything with my own code.
I am working on a WinUI3 project, in the dependencies my frameworks are stated as Microsoft.NETCore.App
and Microsoft.Windows.SDK.Net.Ref
. I need a class to represent a rectangular geometry. I have found an already defined class: https://learn.microsoft/en-us/dotnet/api/system.windows.rect?view=windowsdesktop-9.0
It seems this class is within WindowsBase
assembly that I have within my project under `Microsoft.NETCore.App framework, but I don't know how to reference it https://referencesource.microsoft/#WindowsBase,namespaces
Online it is listed under Windows Desktop 9 (which means Windows Presentation Foundation?), anyway I cannot reference this class from within my project.
Can however reference Windows.Foundation.Rect
https://learn.microsoft/en-us/uwp/api/windows.foundation.rect?view=winrt-26100
but it misses much of the functionality I need such as IntersectsWith(Rect)
, Offset
, etc...
Also can reference System.Drawing.Rectangle
https://learn.microsoft/en-us/dotnet/api/system.drawing.rectangle?view=net-8.0 which is listed under .NET but in the description says is designed for Windows Forms which I heard is to be discontinued
So first, I don't understand why I can access one but not the other, also what should I do? To be honest I spent so much time trying to make sense of it all that perhaps it would be better to implement everything with my own code.
Share Improve this question edited Nov 15, 2024 at 19:23 Eliy Arlev asked Nov 15, 2024 at 19:09 Eliy ArlevEliy Arlev 5782 gold badges4 silver badges16 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 0as Simon Mourier Commented the solution was to add <UseWPF>true</UseWPF>
to .csproj
project file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<UseWPF>true</UseWPF>
However it breaks the project as WinUI auto generated code didn't work propertly.
Was related to How can I reference WindowsBase in .Net5?
<TargetFramework>net8.0-windows</TargetFramework>
for example and<UseWPF>true<UseWPF>
in it, reference that project from your WinUI3 project and you will be able to useSystem.Windows.Rect
fromWindowsBase
. I never mentioned Windows.Foundation.Rect. – Simon Mourier Commented Nov 16, 2024 at 5:17