背景:
GUI 设计可能会遇到的两个阶段:git
评估 GTK#github
若是你须要作复杂界面 / 复杂项目 (参考上面的例子),那么 在没有大量教程参考的状况下,你只能对照 GTK C++ 教程 本身去琢磨对应的 GTK# C# 的实现。 你会哭死。 下一集聊一聊 C# + GTK 开发的另外一种方式: Xamarin.Forms.Platform.GTK 这里 Xamarin Forms 是一个 Renderer https://github.com/jsuarezruiz/xamarin-forms-gtk-samples https://github.com/jsuarezruiz/forms-gtk-progress https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/other/gtk https://www.nuget.org/packages/Xamarin.Forms.Platform.GTK 对比,看看你喜欢哪一个风味 的 API : GTK# 那一套玩意 -> http://zetcode.com/gui/gtksharp 主要 GUI 组件包 是 GTK# (一次开发 多处运行) Xamarin Forms 那一套玩意 -> https://github.com/jsuarezruiz/xamarin-forms-gtk-samples 主要 GUI 组件包 是 Xamarin Forms 涉及到 GTK 的部分仅仅是 “适配” 到 GTK (一次开发 屡次适配 多处运行)
配置步骤:web
https://dotnet.microsoft.com/...macos
brew install gtk+3
windows
dotnet new --install GtkSharp.Template.CSharp
app
brew install glade
工具
dotnet new gtkapp -o MyApp1
cd MyApp1
dotnet run
布局
参考:
https://github.com/GtkSharp/G...
dotnet core 可安装的模板 1
dotnet core 自定义安装模板 2 2
<TargetFramework>netcoreapp2.1</TargetFramework> 是什么 1
GTK+3 1
Glade for GTK+3 1post
命令:
查看全部已安装的 templatesdotnet new --list
依据某个 template 创建项目,好比 console templatedotnet new console -o myApp
学习
GTK#
GtkSharpTutorials 1
更好的办法:
Xamarin Forms 做为 GTK# 的 wrapper,这样就不用学习 GTK 那一套玩意了
参考 https://www.reddit.com/r/dotn...
-=-=-
另外一个理由,为何不用 GTK# ,而用 Xamarin.Forms.Platform.GTK :
一样是 标记语言布局技术, xaml 的可读性 比 glade 好多啦
// 选自 `dotnet new console -o myApp` 生成的 MainWindow.glade // 这是 GUI 组件 主要生效自的地方 <?xml version="1.0" encoding="UTF-8"?> <interface> <requires lib="gtk+" version="3.18"/> <object class="GtkWindow" id="MainWindow"> <property name="can_focus">False</property> <property name="title" translatable="yes">Example Window</property> <property name="default_width">480</property> <property name="default_height">240</property> <child> <object class="GtkBox"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="margin_left">4</property> <property name="margin_right">4</property> <property name="margin_top">4</property> <property name="margin_bottom">4</property> <property name="orientation">vertical</property> <child> <object class="GtkLabel" id="_label1"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Hello World!</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">0</property> </packing> </child> <child> <object class="GtkButton" id="_button1"> <property name="label" translatable="yes">Click me!</property> <property name="visible">True</property> <property name="can_focus">False</property> <property name="receives_default">True</property> </object> <packing> <property name="expand">False</property> <property name="fill">True</property> <property name="position">1</property> </packing> </child> </object> </child> </object> </interface>
// Xamarin.Forms.Platform.GTK 里,由 Xamarin Forms 负责 GUI 组件包 // 这是 GUI 组件 主要生效自的地方 // https://github.com/jsuarezruiz/xamarin-forms-gtk-samples/blob/master/BoxView/TextDecoration/TextDecoration/TextDecoration/MainPage.xaml <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:TextDecoration" x:Class="TextDecoration.MainPage"> <ContentPage.Padding> <OnPlatform x:TypeArguments="Thickness"> <On Platform="iOS" Value="0, 20, 0, 0" /> </OnPlatform> </ContentPage.Padding> <ContentPage.Resources> <ResourceDictionary> <Style TargetType="BoxView"> <Setter Property="Color" Value="Black" /> </Style> </ResourceDictionary> </ContentPage.Resources> <ScrollView Margin="15"> <StackLayout> <AbsoluteLayout> <BoxView AbsoluteLayout.LayoutBounds="0, 10, 200, 5" /> <BoxView AbsoluteLayout.LayoutBounds="0, 20, 200, 5" /> <BoxView AbsoluteLayout.LayoutBounds="10, 0, 5, 65" /> <BoxView AbsoluteLayout.LayoutBounds="20, 0, 5, 65" /> <Label Text="Stylish Header" FontSize="24" AbsoluteLayout.LayoutBounds="30, 25, AutoSize, AutoSize"/> </AbsoluteLayout> <Label> <Label.FormattedText> <FormattedString> <Span Text="The " /> <Span Text="Label" FontAttributes="Italic" /> <Span Text=" and four " /> <Span Text="BoxView" FontAttributes="Italic" /> <Span Text=" elements shown above are children of an " /> <Span Text="AbsoluteLayout" FontAttributes="Italic" /> <Span Text=". This allows the text and its decorations to be precisely sized and positioned." /> </FormattedString> </Label.FormattedText> </Label> <StackLayout HorizontalOptions="Center"> <Label Text="Underlined Text" FontSize="24" /> <BoxView HeightRequest="2" /> </StackLayout> <Label> <Label.FormattedText> <FormattedString> <Span Text="The underlined " /> <Span Text="Label" FontAttributes="Italic" /> <Span Text=" above shares a " /> <Span Text="StackLayout" FontAttributes="Italic" /> <Span Text=" with a " /> <Span Text="BoxView" FontAttributes="Italic" /> <Span Text=", whose width is governed by the " /> <Span Text="Label" FontAttributes="Italic" /> <Span Text=". Unfortunately, you can't use this technique to underline a single word in a paragraph." /> </FormattedString> </Label.FormattedText> </Label> <BoxView HeightRequest="3" /> <Label> <Label.FormattedText> <FormattedString> <Span Text="You can also use a " /> <Span Text="BoxView" FontAttributes="Italic" /> <Span Text=" for a horizontal line. Specify a height but let the width fill the horizontal dimensions of the container." /> </FormattedString> </Label.FormattedText> </Label> <StackLayout Orientation="Horizontal"> <BoxView WidthRequest="4" Margin="0, 0, 10, 0" /> <Label> <Label.FormattedText> <FormattedString> <Span Text="Similarly, you can use a " /> <Span Text="BoxView" FontAttributes="Italic" /> <Span Text=" to mark off a paragraph of text, for example, to indicate a quotation. In this case, the " /> <Span Text="Label" FontAttributes="Italic" /> <Span Text=" and " /> <Span Text="BoxView" FontAttributes="Italic" /> <Span Text=" also share a " /> <Span Text="StackLayout" FontAttributes="Italic" /> <Span Text=", but with a horizontal orientation." /> </FormattedString> </Label.FormattedText> </Label> </StackLayout> <Label> <Label.FormattedText> <FormattedString> <Span Text="What can you use " /> <Span Text="BoxView" FontAttributes="Italic" /> <Span Text=" for?" /> </FormattedString> </Label.FormattedText> </Label> </StackLayout> </ScrollView> </ContentPage>