Created
November 19, 2020 23:49
-
-
Save s0kil/3593281280c8e5c76bb55885a981bb14 to your computer and use it in GitHub Desktop.
Avalonia.FuncUI with Elmish and Live.Avalonia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MyGreatApp | |
open Elmish | |
open Avalonia | |
open Live.Avalonia | |
open Avalonia.Input | |
open Avalonia.FuncUI | |
open Avalonia.Controls | |
open Avalonia.FuncUI.Elmish | |
open Avalonia.FuncUI.Components.Hosts | |
open Avalonia.Controls.ApplicationLifetimes | |
type MainControl() as this = | |
inherit HostControl() | |
do | |
Elmish.Program.mkSimple (fun () -> Counter.init) Counter.update Counter.view | |
|> Program.withHost this | |
#if DEBUG | |
|> Program.withConsoleTrace | |
#endif | |
|> Program.run | |
type App() = | |
inherit Application() | |
interface ILiveView with | |
member __.CreateView(window: Window) = MainControl() :> obj | |
override this.Initialize() = | |
this.Styles.Load "avares://Citrus.Avalonia/Citrus.xaml" | |
override this.OnFrameworkInitializationCompleted() = | |
match this.ApplicationLifetime with | |
| :? IClassicDesktopStyleApplicationLifetime -> | |
let mainWindow = | |
new LiveViewHost(this, (fun msg -> msg |> ignore)) | |
mainWindow.Title <- "2048" | |
let size = 500.0 | |
mainWindow.Width <- size | |
mainWindow.MinWidth <- size | |
mainWindow.MaxWidth <- size | |
mainWindow.Height <- size | |
mainWindow.MinHeight <- size | |
mainWindow.MaxHeight <- size | |
#if DEBUG | |
mainWindow.Renderer.DrawFps <- true | |
mainWindow.Renderer.DrawDirtyRects <- true | |
mainWindow.AttachDevTools(KeyGesture(Key.I)) | |
mainWindow.StartWatchingSourceFilesForHotReloading() | |
#endif | |
mainWindow.Show() | |
| _ -> () | |
module Program = | |
[<EntryPoint>] | |
let main (args: string []) = | |
AppBuilder | |
.Configure<App>() | |
.UsePlatformDetect() | |
.UseSkia() | |
.StartWithClassicDesktopLifetime(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment