/BindingSharp

BindingSharp enables MVVM-Style programming with GTKSharp. It is a library to bind properties of a GTK widget to a viewmodel.

Primary LanguageC#GNU Lesser General Public License v2.1LGPL-2.1

BindingSharp

Note: As GtkSharp will probably not gain support for INotifyPropertyChanged this project will be rebased on gir.core as it's successor as soon as there are Nuget packages available.

BindingSharp enables MVVM-Style programming with GTKSharp. It is a library to bind properties of a GTK widget to a viewmodel.

If you have a .NET Standard 2.0 or .NET CORE application you can port it's view to GTK and reuse the rest of your code to be deployed on Windows, Linux and MacOs with differnt native UI toolkits.

Features

Using

To use the binding the application must provide the viewmodel to the view to be able to create the binding inside the view.

For a complete sample see the Sample App.

  1. Create a view class with a matching glade file which describes the user interface as XML. Inside your view reference some UI widgets in fields. For working examples see the templates of GtkSharp.

  2. Add the PropertyBindingAttribute or CommandBindingAttribute or ValidationBindingAttribute to a widget of your UI

  3. Call Bind(object obj) in your view's constructor to setup the binding

     public class MyWidget : Box
     {
         ...
    
         [UI]
         [CommandBinding(nameof(ViewModelClass.MyCommand))]
         private Button MyButton;
    
         public MyWidget(object viewmodel) : this(new Builder("MyWidget.glade")) 
         { 
             this.Bind(viewmodel)
         }
    
         ...
     }
    

Building from source


Note

Currently GtkSharp is missing the support for INotifyPropertyChanged on GLib.Object.

There is a pull request to add this feature. Until the pull request is merged you can use a custom version from GtkSharp from my temporary fork.

To compile the code checkout the GTKSharp fork and put it parallel to this repository (see references in *.csproj files)


There are 3 projects inside the repository:

  • BindingSharp: Project source
  • BindingSharp.Sample: Example gtk application
  • BindingSharp.Test: Unit tests

To build the source code run dotnet build in the corresponding project folder.

To run the sample app execute dotnet run in the BindingSharp.Sample folder.

To test the code run dotnet test in the BindingSharp.Test folder.

License

BindingSharp and its related components are licensed under LGPL v2.1 license.