背景:
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>