• This repository has been archived on 04/Sep/2024
  • Stars
    star
    1,363
  • Rank 34,478 (Top 0.7 %)
  • Language
    C#
  • License
    MIT License
  • Created about 13 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A cross-platform UI toolkit for creating desktop applications with .NET and Mono

This document is an introduction to XWT, a cross-platform UI toolkit for creating desktop applications.

If you have any question about XWT or do you want to contribute a discussion group for XWT is available here:

http://groups.google.com/group/xwt-list

Introduction

Xwt is a new .NET framework for creating desktop applications that run on multiple platforms from the same codebase. Xwt works by exposing one unified API across all environments that is mapped to a set of native controls on each platform.

This means that Xwt tends to focus on providing controls that will work across all platforms. However, that doesn't mean that the functionality available is a common denominator of all platforms. If a specific feature or widget is not available in the native framework of a platform, it will be emulated or implemented as a set of native widgets.

Xwt can be used as a standalone framework to power the entire application or it can be embedded into an existing host. This allows developers to develop their "shell" using native components (for example a Ribbon on Windows, toolbars on Linux) and use Xwt for specific bits of the application, like dialog boxes or cross platform surfaces.

Xwt works by creating an engine at runtime that will map to the underlying platform. These are the engines that are supported on each platform:

  • Windows: WPF engine, Gtk engine (using Gtk#)
  • MacOS X: Cocoa engine (using Xamarin.Mac) and Gtk engine (using Gtk#)
  • Linux: Gtk engine (using Gtk#)

This means for example that you can write code for Xwt on Windows that can be hosted on an existing WPF application (like Visual Studio) or an existing Gtk# application (like MonoDevelop). Or on Mac, you can host Xwt on an existing Cocoa/Xamarin.Mac application or you can host it in our own MonoDevelop IDE.

Getting Started

Open the Xwt.sln with MonoDevelop (or VisualStudio on Windows) and build the solution. You should end up with the libraries that you can use in your project and a couple of sample applications.

Using Xwt in your app

Based on your platform and the backend that you want to use, you need to pick the libraries that you want to use in your project.

  • Windows+WPF: Xwt.dll + Xwt.WPF.dll (requires WPF)
  • Windows+Gtk: Xwt.dll + Xwt.Gtk.dll (requires Gtk#)
  • Linux+Gtk: Xwt.dll + Xwt.Gtk.dll (requires Gtk#)
  • Mac+Gtk: Xwt.dll + Xwt.Gtk.dll (requires Gtk#)
  • Mac+Cocoa: Xwt.dll + Xwt.XamMac.dll (requires Xamarin.Mac.dll)

Hello World

To write your first application, create an empty .NET project in your favorite language in MonoDevelop or Visual Studio and reference the Xwt.dll library. This is the only library that you need to reference at compile time.

This is the simplest Xwt program you can write:

using System;
using Xwt;

class XwtDemo
{
    [STAThread]
    static void Main()
    {
        Application.Initialize(ToolkitType.Gtk);
        var mainWindow = new Window()
        {
            Title = "Xwt Demo Application",
            Width = 500,
            Height = 400
        };
        mainWindow.Show();
        Application.Run();
        mainWindow.Dispose();
    }
}

You use the Application.Initialize() method to get the backend initialized. In this example we are using the Gtk backend. If you want to use another backend, just change the parameter provided to the Initialize() method. Also make sure the appropiate backend DLL is available in the application directory.

Then we create an instance of the Window class, this class exposes two interesting properties, MainMenu which can be used to set the Window's main menu and "Content" which is of type "Widget" and allows you to add some content to the window.

Finally, the Application.Run method is called to get the UI events processing going.

Widget Class Hierarchy

You will be using widgets to create the contents for your application. Xwt.Widget is the abstract base class from which all the other components are created.

Some Widgets can contain other widgets, these are container widgets, and in Xwt those are Canvas, Paned, HBox, VBox and Table. The first two implement a box layout system, while the last one implements a Table layout that allows widgets to be attached to different anchor-points in a grid.

The layout system uses an auto-sizing system similar to what is availble in Gtk and HTML allowing the user interface to grow or shrink based on the contents of the childrens on it.

  • XwtComponent
    • Menu
    • MenuItem
    • Widget
      • Box (Container)
        • HBox (Container)
        • VBox (Container)
      • Button
        • MenuButton
        • ToggleButton
      • Calendar
      • Canvas (Container)
      • Checkbox
      • ComboBox
      • Frame
      • ImageView
      • Label
      • ListView
      • NoteBook
      • Paned (Container)
        • HPaned (Container)
        • VPaned (Container)
      • ProgressBar
      • ScrollView
      • Separator
        • VSeparator
        • HSeparator
      • Table (Container)
      • TextEntry
      • TreeView
    • WindowFrame
      • Window
        • Dialog

For example, the following attaches various labels and data entries to a Table:

var table = new Table();
table.Attach(new Label ("One:"), 0, 1, 0, 1);
table.Attach(new TextEntry (), 1, 2, 0, 1);
table.Attach(new Label ("Two:"), 0, 1, 1, 2);
table.Attach(new TextEntry (), 1, 2, 1, 2);
table.Attach(new Label ("Three:"), 0, 1, 2, 3);
table.Attach(new TextEntry (), 1, 2, 2, 3);

The Application Class

The Application class is a static class that provides services to run your application.

Initialization

The Application.Initialize API will instruct Xwt to initialize its binding to the native toolkit. You can pass an optional parameter to this method that specifies the full type name to load as the backend.

For example, you can force the initialization of the backend to be specifically Gtk+ or specifically Xamarin.Mac based on MacOS. This is currently done like this:

Application.Initialize("Xwt.GtkBackend.GtkEngine, Xwt.Gtk, Version=1.0.0.0");

or:

Application.Initialize("Xwt.Mac.MacEngine, Xwt.XamMac, Version=1.0.0.0");

As you saw from the Hello World sample, toplevel windows are created by creating an instance of the "Xwt.Window" class. This class exposes a couple of properties that you can use to spice it up. The MainMenu property is used to control the contents of the application menus while the "Content" property is used to hold a Widget.

Timers

The Application.TimeoutInvoke method takes a timespan and a Func action method and invokes that method in the main user interface loop.

If the provided function returns true, then the timer is restarted, otherwise the timer ends.

Background Threads

It is very common to perform tasks in the background and for those tasks in the background to later update the user interface. The Xwt API is not thread safe, which means that calls to the Xwt API must only be done from the main user interface thread.

This is a trait from the underlying toolkits used by Xwt.

If you want a background thread to run some code on the main loop, you use the Application.Invoke (Action action) method. The provided "action" method is guaranteed to run on the main loop.

More Repositories

1

mono

Mono open source ECMA CLI, C# and .NET implementation.
C#
11,128
star
2

SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
C#
4,475
star
3

CppSharp

Tools and libraries to glue C/C++ APIs to high-level languages
C#
3,120
star
4

monodevelop

MonoDevelop is a cross platform .NET IDE
C#
2,821
star
5

taglib-sharp

Library for reading and writing metadata in media files
C#
1,278
star
6

Embeddinator-4000

Tools to turn .NET libraries into native libraries that can be consumed on Android, iOS, Mac, Linux and other platforms.
C#
758
star
7

VulkanSharp

Open source .NET binding for the Vulkan API
C#
537
star
8

CocosSharp

CocosSharp is a C# implementation of the Cocos2D and Cocos3D APIs that runs on any platform where MonoGame runs.
C#
493
star
9

monotouch-bindings

A collection of third party bindings for MonoTouch
C#
450
star
10

gtk-sharp

Gtk# is a Mono/.NET binding to the cross platform Gtk+ GUI toolkit and the foundation of most GUI apps built with Mono
C#
428
star
11

t4

T4 text templating engine
C#
393
star
12

sharpen

Sharpen is an Eclipse plugin created by db4o that allows you to convert your Java project into c#
Java
382
star
13

website

Mono's web site.
HTML
354
star
14

libgdiplus

C-based implementation of the GDI+ API
C
311
star
15

ngit

Automated jgit port to c#
C#
261
star
16

monomac

Bindings to create MacOS X applications with Mono.
C#
259
star
17

LineEditor

LineEditor is an interactive line editor for Command Line applications in .NET
C#
234
star
18

SkiaSharp.Extended

SkiaSharp is a cross-platform, comprehensive 2D graphics API for all .NET platforms. And, here is where you will find all sorts of extras that you can use with it.
C#
230
star
19

cxxi

C++ interop framework
C#
199
star
20

xsp

Mono's ASP.NET hosting server. This module includes an Apache Module, a FastCGI module that can be hooked to other web servers as well as a standalone server used for testing (similar to Microsoft's Cassini)
C#
195
star
21

roslyn

Roslyn Compiler - Tracks Mono Patches
C#
185
star
22

docker

Docker images, for the Docker container system
Dockerfile
166
star
23

mono-tools

The mono-tools package contains a series of extra tools for Mono users.
C#
163
star
24

mono-addins

Mono.Addins is a generic framework for creating extensible applications, and for creating add-ins which extend those applications.
C#
163
star
25

moon

Moonlight, an open source implementation of Silverlight for Unix systems
C#
160
star
26

mono-curses

Mono/.NET bindings to the Unix Curses as well as GUI framework for creating text applications with Curses
C#
138
star
27

winforms

Winforms samples for use with Mono's implementation of System.Windows.Forms
C#
133
star
28

aspnetwebstack

Mono branch of Microsoft's ASP.NET WebStack
C#
118
star
29

sdb

A command line client for the Mono soft debugger.
C#
116
star
30

opentk

OpenTK is a set of bindings to OpenGL, OpenCL and OpenAL. This is not the main repository, just a temporary import to allow Mono developers to make changes to this module. Please do not contribute changes here, contribute them to the upstream maintainers at http://www.opentk.com
C#
115
star
31

cocos-sharp-samples

CocosSharp samples
C#
113
star
32

ikvm-fork

A fork of the original cvs based IKVM repository
C#
102
star
33

mono-basic

Visual Basic Compiler and Runtime
Visual Basic .NET
101
star
34

TsToCSharp

Emit C# strongly typed interface code from TypeScript definition files.
TypeScript
92
star
35

mono-upnp

UPNP binding for Mono/.NET
C#
86
star
36

debugger-libs

Debugger libraries
C#
80
star
37

md-website

MonoDevelop WebSite
HTML
79
star
38

dbus-sharp

DBus Sharp
C#
77
star
39

api-doc-tools

.NET Reference API Toolchain
C#
68
star
40

webkit-sharp

C#/CLI bindings to WebKit/Gtk+
C#
68
star
41

sysdrawing-coregraphics

System.Drawing implementation using CoreGraphics.
C#
67
star
42

maccore

MacCore contains the shared code between MonoTouch and MonoMac
C#
63
star
43

Mono.Zeroconf

Cross platform ZeroConf client that works with the underlying ZeroConf stack on the platform for Mono and .NET
C#
60
star
44

mwf-designer

Windows.Forms designer for Mono. Work in progress
C#
44
star
45

heap-shot

C#
43
star
46

cecil-old

ECMA CIL Manipulation Library
C#
42
star
47

mono.posix

POSIX/Unix interface for Mono, .NET and .NET Core. Provides functionality for managed code to access POSIX/Unix features not accessible via the BCL. This repository supersedes the older code in https://github.com/mono/mono
C#
41
star
48

tao

The Tao OpenGL, OpenAL, GLU, FreeGlut bindings for .NET and Mono
C#
38
star
49

monodroid-bindings

Mono for Android Jar Bindings
C#
36
star
50

entityframework

C#
33
star
51

monkeywrench

Continuous build system used by Mono and Moonlight.
C#
33
star
52

linux-packaging-mono

Packaging metadata for mono-project.com packages
32
star
53

reference-assemblies

Binary reference assemblies
C#
32
star
54

mod_mono

Apache module to host the XSP ASP.NET host
C
30
star
55

jurassic

Mono port of the Jurassic JS Engine (http://jurassic.codeplex.com/).
C#
27
star
56

mono-tls

New TLS implementation for Mono.
C#
27
star
57

bockbuild

Build & packaging system, responsible for the Mono project distribution for Mac
Python
26
star
58

xamarin-gtk-theme

C
25
star
59

linux-packaging-msbuild

C#
23
star
60

SkiaSharp-API-docs

SkiaSharp and HarfBuzzSharp API reference docs
PowerShell
22
star
61

uia2atk

Accessibility bridge between UIA and Gnome's ATK
C#
21
star
62

csvorbis

C#
20
star
63

mono-webbrowser

Browser backends for Mono.WebBrowser
C#
18
star
64

moma

Mono Migration Analyzer. A tool to scan compiled assemblies and determine their compatibility with Mono.
C#
18
star
65

olive

Olive is an incubation module used to host new Mono code under development based on Microsoft's APIs. Olive code eventually graduates and is moved into the Mono distribution.
C#
16
star
66

monocov

Mono Code Coverage profiler module
C#
15
star
67

debugger

Mono Hard Debugger
C
15
star
68

monodevelop-flatpak

Makefile
14
star
69

gtk-sharp-ribbon

C#
14
star
70

guiunit

A unit test runner which interoperates with any Gui main loop
C#
13
star
71

repo

This is the mono repo - we'll put everything here
13
star
72

monologue

Monologue is Mono's blog aggregation software for the Mono community
C#
12
star
73

gir-sharp

C# binding generator for GIR format
C#
12
star
74

lb

Lame Blog, the lamest blog engine in the world
C#
12
star
75

WindowsAPICodePack

WindowsAPICodePack as imported from MonoDevelop
C#
11
star
76

gluezilla

C
10
star
77

roslyn-binaries

Pre-built binaries of Roslyn
C#
10
star
78

stetic

The Gtk# GUI designer
C#
10
star
79

pty-sharp

API for managing Unix pseudo-terminals from managed code
C
9
star
80

mono-microthreads

Microthreads implementation built on top of Mono.Tasklets library
C#
9
star
81

gnome-keyring-sharp

Bindings to Gnome's KeyRing APIs
C#
8
star
82

nuget-binary

Temporary repo to hold nuget binaries for use with MonoDevelop
8
star
83

winforms-tools

Open source Windows.Forms tools.
C#
8
star
84

old-code

Old mono code that has not been developed in years
C#
8
star
85

gio-sharp

Bindings to Glib's libgio
C#
8
star
86

gnome-sharp

Bindings to the core Gnome APIs
C#
8
star
87

crimson

C#
8
star
88

mooncodecs

open source codecs that can be plugged into Moonlight or Silverlight applications
C#
7
star
89

rocks

Mono.Rocks is a library of utility functions
C#
7
star
90

release

(Deprecated, no longer used) Tools to manage Mono's releases (scripts, web pages, build files)
HTML
7
star
91

WebAssembly.JSInterop

WebAssembly JSInterop library
JavaScript
7
star
92

linux-packaging-fsharp

Packaging metadata for mono-project.com packages
F#
7
star
93

nuget

Nuget
C#
6
star
94

monohotdraw

Vector drawing program
C#
6
star
95

dbus-sharp-glib

Managed dbus
C#
6
star
96

Mono.Simd.Math

Math library that uses Mono's accelerated Mono.Simd library
C#
6
star
97

eglib

C
6
star
98

heap-buddy

C#
6
star
99

boringssl

Custom version of Boring SSL used by Mono
C
6
star
100

google-sharp

C#
6
star