avalonia add tag
FoggyFinder
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.
Top Answer
FoggyFinder
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":

```text/x-fsharp
open Avalonia.Controls
open Avalonia.Layout

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:

```text/x-fsharp
open System
open Avalonia
open Avalonia.Controls.ApplicationLifetimes
open Avalonia.Markup.Xaml.Styling

type App() =
    inherit Application()

    override x.Initialize() =
        x.Styles.AddRange [ 
            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()
        | _ -> ()

        base.OnFrameworkInitializationCompleted()
```

5. Create `AppBuilder`:

```text/x-fsharp
open Avalonia.Logging.Serilog
[<CompiledName "BuildAvaloniaApp">] 
let buildAvaloniaApp () = 
    AppBuilder.Configure<App>().UsePlatformDetect().LogToDebug()
```

6. Put it all together:


```text/x-fsharp
[<STAThread>][<EntryPoint>]
let main argv =
    buildAvaloniaApp().StartWithClassicDesktopLifetime(argv)
```

Now, all we have to do is run our basic sample:

![_empty.jpg](/image?hash=9aa60a911ae24ba200379b77676f1124d5f0f00a54da3e26f1fd1a52d9131e9e)

And it takes only 42 (:-)) lines of code. Not that bad!
Answer #2
FoggyFinder
F# Avalonia Templates for VS are available in the `	0.9.12.0` version of the `Avalonia for Visual Studio` extension.

There are 2 different templates that match C# behaviour:

* Empty Avalonia project

* MVVM Avalonia project

The second one uses the `Avalonia.ReactiveUI` package and contains simple `ViewLocator`.

Both of them uses `xaml` files for defining views though.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.