[Gtk-sharp-list] How to get CSS style properties from widgets?
Manuel Roth
roth.manuel at googlemail.com
Sun Jul 2 16:53:16 UTC 2017
Hello everyone,
I'm using CSS styling in GTK3 / GTK# and trying to read style properties
by CssProvider.GetStyleProperty(...).
The function returns false all the time. Can you please help me? Minimum
sample is below.
Kind Regards,
Manuel
/***********************************
Setup details / versions:
***********************************/
- Ubuntu: 17.04 64 bit
- libgtk3.0-cil and libgtk3.0-cil-dev: 2.99.3-2
- libgtk-3-0:amd64, libgtk-3-bin, libgtk-3-common, libgtk-3-dev:amd64:
3.22.11-0ubuntu3
- NuGet package: id="gtk-sharp-3" version="3.22.6.4" targetFramework="net45"
/***********************************
Sample code:
***********************************/
using System;
using GLib;
using Gdk;
using Gtk;
namespace Gtk3Test
{
class MainClass
{
public static void Main(string[] args)
{
Gtk.Application.Init();
GtkWindow win = new GtkWindow();
win.ShowAll();
Gtk.Application.Run();
}
}
public class GtkWindow : Gtk.Window
{
private Fixed _fixed1;
private Button _btnTest;
private CssProvider _cssProvider = new CssProvider();
public GtkWindow()
:base("test window")
{
_cssProvider.LoadFromData("#btnTest {font-size: 23px}");
BuildContent();
RegisterEventhandlers();
WidthRequest = 200;
HeightRequest = 200;
}
void RegisterEventhandlers()
{
_btnTest.Clicked += (sender, args) =>
{
var val = new Value();
var paramSpec = new ParamSpec("font-size", null, null,
GType.Int64, true, true);
var success =
_cssProvider.GetStyleProperty(_btnTest.WidgetPath, StateFlags.Normal,
paramSpec.Handle, val);
if (!success)
{
var s = "What am i doing wrong? I'd expect true and
the value of 23...";
}
};
DeleteEvent += (o, args) =>
{
Gtk.Application.Quit();
args.RetVal = true;
};
}
void BuildContent()
{
_fixed1 = new Fixed()
{
Name = "fixed1",
};
_fixed1.StyleContext.AddProvider(_cssProvider,
StyleProviderPriority.Application);
Add(_fixed1);
_btnTest = new Button(_fixed1)
{
Name = "btnTest",
Label = "Test"
};
_btnTest.StyleContext.AddProvider(_cssProvider,
StyleProviderPriority.Application);
_fixed1.Add(_btnTest);
}
}
}
More information about the Gtk-sharp-list
mailing list