XWT is an open-source cross-platform UI toolkit for Mono and .NET. What’s special about XWT is that it is built on top of the native widget toolkit of each supported platform. So rather than a new widget toolkit implemented from scratch it is an abstraction that wraps the native toolkits using a common API. The end goal of XWT is to allow building applications which look and feel native in each platform. Here are some screenshots of a sample application running with the GTK and Cocoa backends:
![]() |
GTK backend |
![]() |
Cocoa backend |
I initially created XWT with the idea of building MonoDevelop on top of it. Around this time last year we had a discussion about how we could improve the look & feel of MonoDevelop in Mac and Windows. MonoDevelop is built with GTK# 2, which worked very well on Linux, but which had (and still has) some issues on other platforms. Although GTK is a cross platform toolkit, not all backends have the same quality, and not all features are completely implemented. So XWT would allow us to have a native look and still reuse most of the code. However, rebuilding MonoDevelop with XWT is a lot of work and we needed to fix the Mac and Windows issues as soon as possible, so we decided to invest our efforts in fixing the most annoying GTK bugs instead of going the XWT route.
Even though we are not going to immediately migrate all of MonoDevelop to XWT, at Xamarin we have started using it for some UI code that needs run in MonoDevelop and Visual Studio. An example of this is the Android designer. The designer is implemented in XWT, and we use the GTK backend when running MonoDevelop and a WPF backend when running on Visual Studio:
![]() |
The designer running on GTK in MonoDevelop |
![]() |
The designer running on WPF in Visual Studio |
XWT vs Native Toolkits
At Xamarin we have always advocated for using the native toolkit of each platform in order to take advantage of all features offered by the platform and be able to build the most visually rich and performant applications. How does XWT fit on this idea?XWT has three important design features:
- User interfaces implemented using XWT can be embedded inside a native UI. It means you can build your application using the native toolkit when you need advanced platform features, and you can use XWT for more simple UI that can be shared.
- XWT backends are built on top of native toolkits, so XWT widgets really look and behave like native widgets.
- XWT is a UI toolkit abstraction, so it’s about abstracting common UI idioms as widgets. XWT will have support for the most common widgets such as entries or buttons, but it will also provide higher level widgets which are more “semantic”. It means that XWT applications will be constrained to use those higher level UI idioms, but each of those idioms can have a platform-specific implementation which takes full advantage of the native toolkit features, and which can abide for the platform UI guidelines.
Design Principles
XWT looks like GTK#. It uses a similar layout model and class names. That’s basically to make it easier to migrate GTK# code to XWT, not because GTK# is superior to everything else (although maybe it is). However, there are notable differences. The API design has an important focus on simplicity and usability. Here are some important differences with respect to GTK:- The widget hierarchy is mostly flat. There is a Widget class and most of other classes directly subclass it. There are no unnecessary infrastructure classes. For example, there is no Container class, any widget can have children if they need to.
- Widgets are visible by default (I still haven’t figured out the reason why they are hidden by default in GTK).
- No concept of GdkWindow. You have a widget, that’s all.
Features
Here are some details about what’s currently supported by XWT:- XWT currently supports 3 backends with different level of development: GTK, Cocoa (Mac) and WPF (Windows).
- XWT can instantiate more than one backend at a time, and run those side by side (with some limitations). For example, you can have XWT use Gtk and Cocoa in the same application, depending on what is hosting your code.
- The basic widget library is mostly complete.
- It has a drawing API, very similar to Cairo.
- There is no visual designer yet, nor any markup language for representing windows. My plan is to use XAML or a simplified version of it.
- XWT can be extended in different ways.
- Applications can create subclasses of XWT widgets, or create new widgets.
- New backends can be plugged into XWT
- Existing backends can be extended
- The API is not yet stable and can change at any time.
Future
The work on XWT will continue, there is still a lot to do. XWT is already already included in the MonoDevelop core. Although we don’t plan to do a big migration effort, we plan to gradually use XWT in the implementation of new features.If you are interested in XWT, you can get the source code from here:
https://github.com/mono/xwt
There is also a mailing list:
http://groups.google.com/group/xwt-list
And an IRC channel:
irc://irc.gimp.org/xwt
Contributions are welcome!
View comments