我在 VS2017 中使用 GTKSharp 将 C/GTK+ GUI 应用程序转换为 C#。我已经安装了这个包 https://www.nuget.org/packages/GtkSharp/3.1.3通过 NuGet。
这是我加载 CSS 的方式(应用程序使用 Glade 文件定义界面):
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+ 不同。例如,
window {
...
}
适用于 C/GTK+ 但不适用于 C#,而
GtkWindow {
...
}
适用于 C# 但不适用于 C/GTK+。然后有一些我似乎根本无法设置样式的小部件。例如,
button {
...
}
在 GTK+ 中工作但是
GtkButton {
...
}
在 C# 中不起作用。我找不到任何关于 GTK# 如何处理 CSS 样式的文档,所以我认为它与 GTK+ 相同。有什么指点吗?
最佳答案
GTKSharp 看起来更像是预期的 GTK3 行为。
Here is the reference manual from developer.gnome.org
Table 1. Selector syntax
部分特别有用。
简而言之,元素以 GTK 类名命名:GtkButton、GtkLabel 等。
对于默认的类列表GTK3 wigets check out the docs talbe of content. .
GTK 按钮是一个不呈现背景的容器 wiget,因此在没有看到您尝试使用该选择器应用的实际 CSS 属性的情况下,我无法告诉您为什么它不起作用,但您可能需要对其进行样式设置内容分开。例如。
GtkButton GtkLabel {
color: lime;
}
选择器本身 GtkButton
应该是正确的。
关于c# - GTKSharp 中的 CSS 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44548008/