GTKSharp中的CSS样式 [英] CSS styling in GTKSharp

查看:216
本文介绍了GTKSharp中的CSS样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在VS2017中使用GTKSharp将C/GTK + GUI应用程序转换为C#.我已经安装了此软件包 https://www.nuget.org/packages/GtkSharp/3.1.3 通过NuGet.

I'm converting a C/GTK+ GUI application to C# using GTKSharp in VS2017. I've installed this package https://www.nuget.org/packages/GtkSharp/3.1.3 via NuGet.

这是我加载CSS的方式(应用程序使用Glade文件定义界面):

Here's how I load up the CSS (the application uses a Glade file to define the interface):

    static void Main(string[] args)
    {
        new Program(args);
    }

    public Program(string[] args)
    {
        Application.Init();

        builder = new Builder();
        Gtk.CssProvider provider = new CssProvider();
        builder.AddFromFile("interface.glade");
        provider.LoadFromPath("style.css");
        builder.Autoconnect(this);

        Gtk.Window window = (Gtk.Window)builder.GetObject("start"); 
        Gtk.StyleContext.AddProviderForScreen(Gdk.Screen.Default, provider, 800); // couldn't find the equivalent to GTK_STYLE_PROVIDER_PRIORITY_USER so I set the priority to a random number
        window.Show();

        Application.Run();
    }

选择器名称似乎与GTK +不同.例如,

The selector names seem to be different from GTK+. For example,

    window {
     ...
    }

可以在C/GTK +中工作,但不能在C#中工作,而

works in C/GTK+ but not in C#, whereas

    GtkWindow {
     ...
    }

在C#中有效,但在C/GTK +中无效.然后有一些我似乎根本无法样式化的小部件.例如,

works in C# but not in C/GTK+. Then there are a few widgets I can't seem to style at all. For example,

    button {
     ...
    }

可在GTK +中使用,但

works in GTK+ but

    GtkButton {
     ...
    }

在C#中不起作用.我找不到任何有关GTK#如何处理CSS样式的文档,因此我认为它与GTK +相同.有指针吗?

does not work in C#. I couldn't find any documentation regarding how GTK# handles CSS styling so I thought it'd be the same as GTK+. Any pointers?

推荐答案

这是版本问题.

GTK的版本 3.22 正确检测到GtkButton选择器.我正在使用GTK 3.14的本机库.有一个未列出的NuGet软件包提供了Win32库适用于3.22版本.奇怪的是,该版本检测到旧的按钮",窗口" ...而不是"GtkButton","GtkWindow" ...标记.

Version 3.22 of GTK# detects the GtkButton selector correctly. I was using GTK 3.14's native libraries. There is one unlisted NuGet package that provides win32 libraries for the 3.22 version. Strangely enough, that version detects the old "button", "window"... instead of the "GtkButton", "GtkWindow"... tags.

这篇关于GTKSharp中的CSS样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆