问题
Let's say just for the joy of it, I decide that I don't want to write desktop applications in Java any more, instead want to switch to using C#. I want to be able to build an application that will run on some mainstream Linux distribution, and a recent release of MS Windows. It will have a GUI component.
In Java I can build an application that uses Swing. Once I have it working, I can copy that jar file from Windows to Linux or vice versa, depending where I developed it. And it will generally run with java -jar myapp.jar
.
In C# is it possible to do this? Is there a functional equivalent to Swing or AWT in C#?
回答1:
There's Eto.Forms (on github), which is an abstraction layer on top of WPF, WinForms, GTK, and MonoMac/Cocoa - so you can get a native UI on all platforms without having to re-implement for each platform. You don't have to suffer from lowest common denominator, since you can implement specifics for each platform (if desired, but not required).
It has an advantage that it is pure .NET and only relies on OS-supplied dependencies, as opposed to using GTK or WxWidgets where you'd have to bundle the native binaries for various platforms.
回答2:
Probably GTK# would be the closest.
I know others have said mono, but that's not quite right. .Net is to mono as Microsoft's Java VM is to Sun's Java runtime. mono's not really in the same conceptual space as Swing. For that, GTK# is a closer match.
回答3:
I believe a good portion of WinForms is implemented in Mono. You need to install Mono under Linux for that. You may have compatibility problems, though, since Mono is not a Microsoft effort and is not officially supported by them.
回答4:
This page has a list of the GUI toolkits supported by Mono, including pros and cons for each of them. As others have suggested, WinForms, GTK#, and wxNet are all viable options.
回答5:
You can try WxWidgets. It has support for C#, among many other languages, and is cross-platform. The only downside being a recompile for each platform. Alternatively you can try Mono which is very good, but beware there are a couple snags with compatibility issues. There is no predefined "run anywhere" file for C# apps yet like Java has with jars though, you're best bet is to recompile for each platform if you want to ensure compatibility.
回答6:
This is an older question, but as an update, a combination of Mono and Xamarin should work for your modern cross-platform needs.
http://www.mono-project.com/docs/gui/winforms/
Microsoft has just open-sourced .NET and is committing to bringing the .NET core to Linux and MacOS with their next version. Microsoft has also formed a close partnership with Mono and Xamarin, specifically to help with their Android and Linux libraries.
http://www.hanselman.com/blog/AnnouncingNET2015NETAsOpenSourceNETOnMacAndLinuxAndVisualStudioCommunity.aspx
回答7:
The closest thing I've ever seen is Mono - though it doesn't support all the CLR libraries yet I believe, but it is cross-platform.
回答8:
For iOS, Android, and Windows Mobile, there is Xamarin.Forms. http://xamarin.com/forms This is an abstraction layer that allows you to write cross-platform code, which binds to the native GUI toolkits under the hood.
I am looking for more solutions like this - I care not only about mobile platforms, but also desktop platforms (windows, mac OSX, fedora/ubuntu/etc linux)
回答9:
Windows.Forms is the standard library for developing GUI applications for .NET
Despite of being very well supported on Windows, version 2.0 is fully implemented by Mono too, which makes it available on all platforms supported by Mono.
WPF on the other hand is is conceptually new library, for now it is fully supported mainly on Windows only and just a subset of it supported by Mono by their Silverlight implementation - Moonlight.
If you are building application for productive cross-platform use and/or have conservative performance constraints go Windows Forms.
If you want to experiment and learn something new or if you are developing new application for Windows go WPF. This is the new technology for client GUI applications.
回答10:
There are plenty these days. It depends on what you are looking for. Here is a detailed write-up about these three choice technologies. They are not the only technologies, but they have the most buzz around them right now.
Xamarin Forms
C#, XAML Based, Microsoft owned Open Source, Supports Android, iOS, UWP, and more. Native rendering.
Uno Platform
C#, XAML Based, Open Source, Supports Android, iOS, UWP, and more. Native rendering.
Avalonia
C#, XAML Based, Open Source, Supports Linux, MacOS, Windows, and more. Pixel perfect rendering on each platform.
来源:https://stackoverflow.com/questions/779283/is-there-a-cross-platform-gui-framework-for-c-net