Skip to content

2.0 Release

Compare
Choose a tag to compare
@cwensley cwensley released this 14 Nov 08:36
· 3177 commits to develop since this release

Eto.Forms v2.0 is a culmination of many major updates to the API which bring a more declarative API, better binding API's, INotifyCollectionChanged support in many controls, and numerous bug fixes in all platforms.

Since 1.3, there have been a whopping 475 commits over 6 months.

New Features

Some great new features are in this release!

First and foremost, Eto.Forms is transitioning to a PCL (Portable Class Library) for its core and is now default when targetting .NET 4.5. The .NET 4.0 assemblies are still kept for compatibility with older versions of mono (< 3.2), mainly to support standard distributions like Ubuntu.

Also, the entirety of Eto.dll is now fully commented and comes along with the nuget package, so intellisense should give you better information on what things do. If there are any comments that need better descriptions, please file an issue with the specific methods/classes.

New Controls

These new controls are supported on all desktop platforms:

  1. Calendar - Shows a calendar directly in the form, with MinDate, MaxDate, and can select a range or a single date.
  2. ColorPicker - Used to show and allow the user select a color. Uses the appropriate picker dialog for each platform, e.g. on OS X it is a standard color tool window, whereas on windows it will show a drop down picker.
  3. LinkButton - Simple text that acts like a button, similar to a hyperlink on a web page.
  4. RadioToolItem - Radio button for a toolbar, so you can create dialogs similar to preference dialogs in OS X, or have alternating options. CheckToolItem is also fixed on OS X to be a standard toggle button that can be on or off.
  5. DrawableCell - A new cell for the GridView or TreeGridView that allows you to paint the contents using Eto.Drawing.
  6. ComboBox - The old ComboBox was renamed to DropDown, and now is a combination of a text entry box and a drop down with all the expected functionality and behaviour consistent on all platforms.

New Platforms

Now with this release, Eto.Platform.iOS and Eto.Platform.XamMac2 (unified) packages are on nuget.org. You can now use Eto.Forms on Xamarin.iOS and 64-bit Xamarin.Mac projects!

Note that there are some desktop-level controls that are not supported on iOS, please see details on how to detect Partially Supported Functionality for each platform.

TableLayout declarative API

The TableLayout has had a lot of love poured into it to make it more useful out of the box. Instead of determining the size of the table then adding controls to each cell manually, you can now use its new Rows property and add rows and cells directly.

For example, in 1.3 you would have to do this:

var layout = new TableLayout(3, 3);
layout.Add(myLabel, 1, 1);
layout.Add(myButton, 1, 2);
layout.SetColumnScale(0);
//...

Now, you can do this with constructors:

var layout = new TableLayout(
    null,
    new TableRow(null, myLabel, myButton),
    null    
}

Or, use TableLayout.Rows and TableRow.Cells with the initializer pattern so you can easily set other properties at the same time:

var layout = new TableLayout {
    Padding = new Padding(10),
    Spading = new Size(5, 5),
    Rows = {
        null,
        new TableRow {
            ScaleHeight = true,
            Cells = { null, myLabel, myButton }
        },
        null
    }
}

Currently you cannot modify the rows/cells after you add the layout to your form, but this is planned for a future release. DynamicLayout will continue to be supported, but the recommended way forward will be to use the TableLayout directly.

MenuBar Improvements

The MenuBar has always had a loose method of getting a native feel on all platforms. You would have to create the menu differently depending on the running platform to get the About, Help, Quit, and other application-level items in their right location.

Now, the menu bar supports many new properties directly so you can set these items and it will put them in their right location on all platforms for you. It also supports creating your menu declaratively like so:

Menu = new MenuBar
{
    Items = {
        // main items
        new ButtonMenuItem { Text = "&File", Items = { clickMe } },
        new ButtonMenuItem { Text = "&Edit", Items = { /* commands/items */ } },
        new ButtonMenuItem { Text = "&View", Items = { /* commands/items */ } },
    },
    ApplicationItems = {
        // application (OS X) or file menu (others)
        new ButtonMenuItem { Text = "&Preferences..." },
    },
    QuitItem = quitCommand,
    AboutItem = aboutCommand
};

As you can notice, there's also no order for each item, making things really simple. You can still set the order of your items making merging of items super easy, but it is no longer requried.

Enhanced Binding API's

Binding to controls has been flushed out to provide flexability but consice declaration of binding to your objects either directly or through the DataContext.

For example, you can now specify lambda's to get property values. If the lambda evaluates to a property expression, then it will use reflection to set the value and attach changed events.

using Eto.Forms;
class MyClass
{
    public string MyText { get; set; }
    public bool Enabled { get; set; }
}

class MyForm : Form
{
    public MyForm()
    {
        var myClass = new MyClass { MyText = "someText" };
        DataContext = myClass;

        var textBox = new TextBox();

        // bind using the current DataContext
        // advantage of this, is you can change the DataContext,
        // and the controls will update for the new context.
        textBox.TextBinding.BindDataContext<MyClass>(r => r.MyText);
        // bind to the Enabled property
        textBox.BindDataContext(tb => tb.Enabled, (MyClass r) => r.Enabled);


        // bind directly
        textBox.TextBinding.Bind(myClass, r => r.MyText);
        // different property of the textBox
        textBox.Bind(tb => tb.Enabled, myClass, r => r.Enabled);
    }
}

Easier integration with native applications

Each platform assembly now has extensions added to the Eto.Forms namespace to convert native controls to Eto controls and vise versa.

This will make it much easier to use Eto.Forms when integrating it into your existing application. Samples have been added that demonstrate this for each of the platforms.

Performance improvements

There have been some performance improvements over the framework, mainly in layout. You'll notice drastic improvements in the WinForms platform with better suspend/resume logic in the backend so you don't have to lift a finger for things to just work well.

Breaking Changes

Following the popular SemVer, a major version change brings breaking changes. However, where possible, API's were obsoleted instead of removed allowing for a more seamless upgrade path.

Unfortunately, there were some changes that cannot be gracefully obsoleted and will mean you have to make some minor changes.

Here is a list of things that may break coming from v1.3 code:

1. TableLayout Padding and Spacing are now zero by default

The TableLayout no longer defaults to 10 padding around the border and 5x5 spacing between cells. To get the previous behaviour, you can use a style before starting your app, like this:

Eto.Style.Add<Eto.Forms.TableLayout>(null, table => {
    table.Padding = new Eto.Drawing.Padding(10);
    table.Spacing = new Eto.Drawing.Size(5, 5);
});

2. ComboBox is dead. Long live the ComboBox!

The ComboBox UI control was renamed to DropDown. However a proper ComboBox, according to wikipedia, is a combination of an entry text box and a drop down. Now both exist in Eto.Forms, along with all of the expected properties and events, such as AutoComplete, ReadOnly, Text, and TextChanged. New samples have been added that flex the new ComboBox's muscles so go check it out!

3. DataStore is now IEnumerable<object> in most cases

The IDataStore and IDataStore<T> are now mostly removed in favour of using standard collections. Most controls will bind using the INotifyCollectionChanged interface to update the UI when the collection changes automatically. You can use the standard ObservableCollection<T> which implements INotifyCollectionChanged. The only remaining controls that do not use this mechanism yet is the TreeView and TreeGridView. This is planned for a future version.

4. Platform assemblies and namespaces renamed

If you have only written UI code using Eto.dll, then this will not affect you. However, the platform assemblies are now simplified from Eto.Platform.[platform].dll to Eto.[platform].dll. This means all of the handlers and code are in a different namespace. The nuget packages still have the same name

5. Virtualized Eto.IO is now removed

This was probably not used much (if at all), so it is removed to keep Eto.Forms' code clean of any unnecessary functionality.

6. On[Event] methods are now protected instead of public

To better conform to .NET standard practices, all event handler methods in classes are now protected to prevent them from being called outside the class. This means if you had code like:

public class MyButton : Button {
{
    public override void OnClick(EventArgs e)
    {
        //...
    }
}

It should now be changed to:

public class MyButton : Button
{
    protected override void OnClick(EventArgs e)
    {
        //...
    }
}

7. Static methods with Generator parameter are now static properties

In 2.0, the need to pass the Generator (now Platform) to methods and constructors has been drastically reduced, to the point that you pretty much don't need to worry about it anymore. In doing so, there were some static methods in Eto.Drawing that have been changed. Mainly, these are the helper methods to get pens, brushes, mouse positions, etc. For example:

  • x.IsSupported() becomes x.IsSupported
  • Pens.<Color>() becomes Pens.<Color> (e.g. Pens.White)
  • Brushes.<Color>() becomes Brushes.<Color> (e.g. Brushes.Green)
  • Mouse.GetPosition() & Mouse.GetButtons() becomes Mouse.Position & Mouse.Buttons

8. Obsolete code removed

All functionality that was marked as obsolete in 1.3 is now removed. Anything that compiled without warnings in 1.3 should mostly compile in 2.0, with a few (hopefully) minor modifications. Anything marked as obsolete will be removed soon in the develop branch, which will become version 2.1 when released.

This means that before upgrading from 2.0 to 2.1, you should ensure to resolve all obsolete warnings.

Questions & Thanks

If there are any questions about the new release or its features, feel free to talk about it in the forums or on irc. Any issues should be filed in the github issue tracker.

I also want to thank all of the contributors to Eto.Forms that have submitted pull requests, created issues, added information on the wiki, or just spreading the word!