我有使用在Mac上运行的Mono Framework和GTK UI的C#App。我在Filechooser对话框的外观上有问题。按照https://developer.gnome.org/gtk3/stable/GtkFileChooserDialog.html我应该得到这些图标
但我得到的是左侧面板中没有正确图标或驱动器图标的驱动器。对于驱动器,有一个名为Volumes的文件夹,用户需要手动打开它。我认为这不是本机Mac用户所期望的。我发布了从网上获得的2张截图。
我有这个GTK版本(2.2)与Mono for Mac捆绑在一起。我应该怎样做才能获得更原生的外观和感觉?请建议
答案 0 :(得分:4)
您可以使用较旧的开源MonoMac或较新的Xamarin.Mac来打开NSOpenPanel并使用本机OS-X文件选择器而不是基于xplat的GTK 2版本。
只要您记得通过MonoMac静态方法 // ----------------------------------------------------------------------------
// Mixins
// ----------------------------------------------------------------------------
@mixin transition($transition-property, $transition-time, $method) {
-webkit-transition: $transition-property $transition-time $method;
-moz-transition: $transition-property $transition-time $method;
-o-transition: $transition-property $transition-time $method;
transition: $transition-property $transition-time $method;
}
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #12b0c5;
$value-color: #fff;
$title-color: rgba(255, 255, 255, 0.9);
$label-color: rgba(255, 255, 255, 0.9);
$moreinfo-color: rgba(2, 2, 2, 0.6);
// ----------------------------------------------------------------------------
// Widget-list styles
// ----------------------------------------------------------------------------
.widget-hotlist {
background-color: $background-color;
vertical-align: top !important;
@include transition(background-color, 0.5s, linear);
.title {
color: $title-color;
font-weight: 800;
}
ol, ul {
margin: 0 15px;
text-align: left;
color: $label-color;
}
ol {
list-style-position: inside;
}
li {
margin-bottom: 5px;
}
.list-nostyle {
list-style: none;
}
.label {
color: $label-color;
}
.value {
float: right;
margin-left: 12px;
font-weight: 800;
color: $value-color;
}
.updated-at {
color: rgba(0, 0, 0, 0.3);
}
.more-info {
color: $moreinfo-color;
}
}
.hotness0 { background-color: #00C176; }
.hotness1 { background-color: #88C100; }
.hotness2 { background-color: #FABE28; }
.hotness3 { background-color: #FF8A00; }
.hotness4 { background-color: #FF003C; }
初始化应用程序,就可以在GTK#之上混合使用MonoMac对话框。在应用程序启动时尽早执行此操作,但在GTK#初始化之后。
至于打开原生NSOpenPanel,这是GTK#Button点击处理程序中使用的示例:
NSApplication.Init()
注意:将调用包装在button.Clicked += (object sender, EventArgs e) => {
Application.Invoke (delegate {
var nsOpenPanel = new NSOpenPanel ();
nsOpenPanel.ReleasedWhenClosed = true;
nsOpenPanel.Prompt = "Select file";
var result = nsOpenPanel.RunModal ();
if (result == 1) {
button.Label = nsOpenPanel.Url.ToString ();
}
});
};
委托中总是明智的,这样一切都在主GTK UI线程上执行。