How to load a GTK Sharp theme on MS Windows

半腔热情 提交于 2019-12-21 20:38:44

问题


I'm programming a GTK Sharp (v2.12) application using Xamarin Studio 5.4 on MS Windows. The installed Mono version is 3.2.3 (but I'm using the .Net tool chain to compile, because Xamarin doesn't allow me to compile using the Mono toolchain).

The case is that when I run the application from the Xamarin Studio or using Mono, then I have a relatively nice look & feel, but when I run the application using .Net (doing double click on the executable) then the look & feel is horrible.

I've tried to trick the application to load a decent theme... but it does nothing when I do it from .Net (but when I'm using Mono then it's easy to see the changes).

This is the code I've tried but that does not work (I have a local copy of the GTK themes rc files):

// It works on Mono, but not on .Net
Gtk.Rc.Parse("Resources/GTK/windows-theme.gtkrc");

I've also tried to do:

// This does not work at all (on MS Windows)
Gtk.Settings.Default.ThemeName = "MS-Windows";

But this does not change anything, even using the Mono engine.

This is how the application looks using Mono:

And how it looks running under the .Net engine:

Thanks for your attention :) .


回答1:


Well, I've found the answer to my question :D .

I didn't try to load a specific GTK theme, but solved it to make .Net working properly without having to copy all the DLL files in the program directory.

I've found this thread in the Xamarin development forums:

  • http://forums.xamarin.com/discussion/15568/unable-to-load-dll-libgtk-win32-2-0-0-dll

In this thread Xamarin developers explain how they solve the dependencies loading problem. The key is to call the CheckWindowsGTK method before the Application.Init() call. The CheckWindowsGTK is defined in this file from the Monodevelop sources:

  • https://github.com/mono/monodevelop/blob/master/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs#L490-L490

HINT: It's important to call CheckWindowsGTK only if the program is running on Windows.



来源:https://stackoverflow.com/questions/25972700/how-to-load-a-gtk-sharp-theme-on-ms-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!