简体   繁体   English

如何添加程序集引用以在 c# 中使用 Rect?

[英]How do I add the assembly reference to use Rect in c#?

I want to use the Rect Struct and I write Rect aaa = new Rect();我想使用Rect结构,我写Rect aaa = new Rect(); and I get the type or namespace could not be found error.我得到the type or namespace could not be found错误。 I try adding all the using s as in the example of the web:我尝试添加所有using s,如网络示例中所示:

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

and I get in that the last three imports a the type or namespace Shapes does not exist in the namespace System.Windows. (are you missing an assembly reference?)我发现最后三个导入了the type or namespace Shapes does not exist in the namespace System.Windows. (are you missing an assembly reference?) the type or namespace Shapes does not exist in the namespace System.Windows. (are you missing an assembly reference?) . the type or namespace Shapes does not exist in the namespace System.Windows. (are you missing an assembly reference?)

At the webpage mentioned, it says the assembly is WindowsBase.dll .在提到的网页上,它说程序集是WindowsBase.dll And now I don't know how to go on...现在我不知道如何继续......

UPDATE: I've been told to add a reference, but it's a Core project and that's not possible .更新:我被告知要添加一个参考,但它是一个核心项目, 这是不可能的

I should install a package but I don't see any package containing this dll.我应该安装一个包,但我没有看到任何包含这个 dll 的 The package WindowsBase is not valid for .net 5, but in the documentation above it says this Struc can be used indeed with .net 5. WindowsBase 包对 .net 5 无效,但在上面的文档中它说这个 Struc 确实可以与 .net 5 一起使用。

I want to use this struct.我想使用这个结构。

Short answer: As @imsmn commented, add a reference to WindowsBase.简短回答:正如@imsmn 所评论的,添加对 WindowsBase 的引用。 Do that by right clicking on the "References" entry in the Solution explorer and select "Add Reference".通过右键单击解决方案资源管理器中的“引用”条目并选择“添加引用”来执行此操作。

Long answer (or more accurately, suggestion):长答案(或更准确地说,建议):

Easy way to get the answer in the future: For "built-in" classes that are not ambiguous, you can try this.将来获得答案的简单方法:对于没有歧义的“内置”类,您可以尝试这个。 In Visual Studio, in the code window (C# editor) type:在 Visual Studio 中,在代码窗口(C# 编辑器)中键入:

Rect r = new Rect();

Then hold your mouse over the red squiggly line that appears under the word "Rect".然后将鼠标悬停在出现在“Rect”一词下方的红色波浪线上。 A box will pop-up and one of the options will be "Show Potential Fixes".将弹出一个框,其中一个选项是“显示潜在修复”。 If you click that, one of the options is often to add the reference (if necessary) and the using directive (if necessary).如果单击它,选项之一通常是添加引用(如果需要)和 using 指令(如果需要)。

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

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