如何在非特定于Windows的.NET 6.0应用程序中选择目录?

huangapple go评论78阅读模式
英文:

How to select a directory in a non Windows-specific .NET 6.0 application?

问题

我想向用户呈现一个对话框,允许他们从文件系统中选择一个目录。根据我在网上找到的信息,可以使用 FolderBrowserDialogOpenFileDialog 类来实现这个目标。然而,它们都位于 System.Windows.Forms 中,但编译器声称在 System.Windows 中没有 Forms 命名空间。

我尝试通过Visual Studio添加引用,还尝试手动在我的 .csproj 文件中添加 <UseWindowsForms>true</UseWindowsForms>,但都没有成功。大多数关于这个主题的问题都来自.NET Core是当前.NET版本的时代。

根据我找到的一些最新回答,似乎应用程序必须是特定于Windows的,才能使用 System.Windows.Forms(这听起来是合理的)。不幸的是,我的应用程序需要跨平台,并且在Linux下工作。在这种情况下,是否有任何方法可以显示一个选择目录的对话框?

英文:

I want to present the user with a dialog that allows them to select a directory from the file system. According to what I found online, this can either be done with the FolderBrowserDialog or OpenFileDialog classes. However, both of them live in System.Windows.Forms, but the compiler claims that there is no Forms namespace in System.Windows.

I have tried to add a reference through Visual Studio and I also tried adding <UseWindowsForms>true</UseWindowsForms> to my .csproj-file manually, but to no avail. Most of the questions surrounding this topic are back from the days where .NET Core was the current .NET version.

From the few up-to-date answers I found, it seems like the application has to be Windows-specific, in order to use System.Windows.Forms (which sounds logical). Unfortunately, my application needs to be multi-platform and also work under Linux. Is there any way I can show a dialog to select a directory under these circumstances?

答案1

得分: 2

目前,Microsoft没有为C#提供适用于Linux的内置UI框架。要监视“跨平台”MAUI的Linux支持,您可以关注此GitHub问题。但也有其他选择,例如AvaloniaUI,这是一个相当受欢迎的.NET UI框架,支持Linux。

英文:

Currently there is no build-in/provided by Microsoft UI framework for C# which supports Linux. To monitor Linux support for "cross-platform" MAUI you can follow this github issue. But there are alternatives, for example - AvaloniaUI - a quite popular UI framework for .NET which supports Linux.

答案2

得分: 1

抱歉,无法执行该操作。

如果您想自己创建对话,您可以使用MAUI,但不幸的是,“官方”版本不包括Linux。

英文:

Sorry, no way to do that.

If You want to create a dialog yourself, you can use MAUI, but unfortunately the "official" version doesn't include Linux.

huangapple
  • 本文由 发表于 2023年3月3日 20:30:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75627107.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定