Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Sep 4, 2024. It is now read-only.
/xwtPublic archive

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

License

NotificationsYou must be signed in to change notification settings

mono/xwt

Repository files navigation

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

If you have any question about XWT or do you want to contributea 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 runon multiple platforms from the same codebase. Xwt works by exposingone unified API across all environments that is mapped to a set ofnative controls on each platform.

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

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

Xwt works by creating an engine at runtime that will map to theunderlying platform. These are the engines that are supported oneach 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 thatcan be hosted on an existing WPF application (like Visual Studio) oran existing Gtk# application (like MonoDevelop). Or on Mac, you canhost Xwt on an existing Cocoa/Xamarin.Mac application or you can host itin our own MonoDevelop IDE.

Getting Started

Open the Xwt.sln with MonoDevelop (or VisualStudio on Windows) andbuild the solution. You should end up with the libraries that youcan 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 needto 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 yourfavorite language in MonoDevelop or Visual Studio and reference theXwt.dll library. This is the only library that you need to referenceat compile time.

This is the simplest Xwt program you can write:

usingSystem;usingXwt;classXwtDemo{[STAThread]staticvoidMain(){Application.Initialize(ToolkitType.Gtk);varmainWindow=newWindow(){Title="Xwt Demo Application",Width=500,Height=400};mainWindow.Show();Application.Run();mainWindow.Dispose();}}

You use theApplication.Initialize() method to get the backendinitialized. In this example we are using the Gtk backend. If youwant to use another backend, just change the parameter providedto theInitialize() method. Also make sure the appropiate backendDLL is available in the application directory.

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

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

Widget Class Hierarchy

You will be using widgets to create the contents for yourapplication. Xwt.Widget is the abstract base class from which allthe 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 firsttwo implement a box layout system, while the last one implements aTable layout that allows widgets to be attached to differentanchor-points in a grid.

The layout system uses an auto-sizing system similar to what isavailble in Gtk and HTML allowing the user interface to grow or shrinkbased 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 toa Table:

vartable=newTable();table.Attach(newLabel("One:"),0,1,0,1);table.Attach(newTextEntry(),1,2,0,1);table.Attach(newLabel("Two:"),0,1,1,2);table.Attach(newTextEntry(),1,2,1,2);table.Attach(newLabel("Three:"),0,1,2,3);table.Attach(newTextEntry(),1,2,2,3);

The Application Class

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

Initialization

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

For example, you can force the initialization of the backend to bespecifically Gtk+ or specifically Xamarin.Mac based on MacOS. This iscurrently 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 createdby creating an instance of the "Xwt.Window" class. This classexposes a couple of properties that you can use to spice it up. TheMainMenu property is used to control the contents of the applicationmenus while the "Content" property is used to hold a Widget.

Timers

The Application.TimeoutInvoke method takes a timespan and a Funcaction method and invokes that method in the main user interfaceloop.

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 thosetasks in the background to later update the user interface. The XwtAPI is not thread safe, which means that calls to the Xwt API mustonly 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, youuse the Application.Invoke (Action action) method. The provided"action" method is guaranteed to run on the main loop.

About

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

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp