Gtk#

Matt Perley
2 min readSep 20, 2020

If you use C# and .Net you are probably well aware of winforms, WPF and UWP. These frameworks allow you to design UI for your applications. What happens though when you want or need to write cross platform code? There are a number of really great libraries that provide this functionality. One such library is Gtk#.

Gtk# is a wrapper around the Gtk+ library. It includes a number of other api’s like Cairo# or Gdk that add text, font and other features to the package. You can use Gtk 2 with Mono in Monodevelop. Monodevelop provides a Visual Studio like GUI designer (stetic) to build your widget and window layouts. Monodevelop can be downloaded from: https://www.monodevelop.com/download/.

Outside of Monodevelop and Mono you can use Gtk# 3 as a nuget in a .Net Core project. You can use Visual Studio Code to write code and debug your Gtk# applications. The .Net Core route however does require you to use Glade instead of stetic to create your UI. If you have worked with Xml before you will be able to understand whats going on pretty quick. You can add Gtk to your .Net Core project by using: dotnet add package GtkSharp — version 3.22.25.128, to get started. Alternatively you can use: dotnet new — install GtkSharp.Template.CSharp, and then: dotnet new gtkapp, to make a new app straight from the terminal.

I will likely cover Gtk many more times in the future. Its a framework I use frequently, especially for Linux development. It has some quirks and oddities I would like to cover and a number of things that are fairly different from their Winforms or WPF counterparts. I am going to do some one off posts, in between doing some upcoming ML blogs, that explain how to use individual widgets in C# using .Net Core.

What are your thoughts or experiences with Gtk? Was it a nightmare? Or did you have a fair amount of success from using it?

Until next time, take care.

--

--