Docs [says](Avaloniaui.net/docs/) that Avalonia lets use any .NET languages. But [currently](https://github.com/AvaloniaUI/avaloniaui.net/issues/115) all sections are about C#: documentation even doesn't contain getting started guide for F#.
Besides all available Avalonia templates for `dotnet new` are only for C#.
Yet one concern is that XAML, probably, doesn't fit well to F#. So I'd also like to see how write application without it.
How to create almost empty F#-Avalonia application:
1. Create console .net core app (Avalonia has support for .net Framework but better option would be .net core nevertheless)
2. Add reference to [Avalonia.Desktop](https://www.nuget.org/packages/Avalonia.Desktop/) package.
3. Write the View. Since it is a very simple sample let's create Window that contains single TextBlock that shows "F# Avalonia app":
type MainWindow () as self =
inherit Window ()
let txb = TextBlock(Text = "F# Avalonia app",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center)
do self.Content <- txb
4. Add App:
type App() =
override x.Initialize() =
new StyleInclude(baseUri=null, Source = Uri("resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default"))
new StyleInclude(baseUri=null, Source = Uri("resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default"))
override x.OnFrameworkInitializationCompleted() =
match x.ApplicationLifetime with
| :? IClassicDesktopStyleApplicationLifetime as desktop ->
desktop.MainWindow <- new MainWindow()
| _ -> ()
5. Create `AppBuilder`:
let buildAvaloniaApp () =
6. Put it all together:
let main argv =
Now, all we have to do is run our basic sample:
And it takes only 42 (:-)) lines of code. Not that bad!