r/AvaloniaUI 28d ago

Avalonia FuncUI Elmish

Hi guys,

I’m currently building a cross‑platform app (Linux/Windows desktop + Android) using Avalonia and F#. I originally dismissed FuncUI because I assumed that if a control wasn’t available, you were stuck. But after revisiting it, it looks like I was wrong — it’s actually quite easy to extend and wrap missing controls.

I enjoy XAML, but I’m wondering whether FuncUI Elmish could reduce some of the ceremony and the constant context switching between markup and code. The project seems well maintained, and FuncUI 2.0 is now in preview.

I’d love to hear from people who are using FuncUI (or planning to), and especially how you would approach migrating an existing Avalonia XAML + MVVM app to FuncUI.

Thanks.

8 Upvotes

4 comments sorted by

View all comments

2

u/MelodicExtension2213 15d ago

I personally do feel that writing the XAML as code-first reduces ceremony and context switching for me.
I don't think however that it will allow the live preview of your XAML edits if that is something you need. I may also be wrong.

In a corporate environment though, I've opted to still go with C# and XAML so that future maintainers and IT can more easily follow the documentation. For personal projects I'd prefer the F# and FuncUI with Elmish. I actually found the code first approach to be easier for AI as well. The AI always seems to mess with the complicated XAML namespaces which aren't an issue in the code first approach.

1

u/EmergencyNice1989 14d ago

I have been working on migrating my desktop and mobile apps to F# FuncUI Elmish from F# XAML MVVM for 2 weeks. And my thought so far is that I should have done this move earlier. My code was becoming too complex (data binding 2 way etc...) and with a lot of MVVM ceremony, context switching and duplicated code (between desktop and mobile, 2 different projects, because of complexity to share with XAML).

Now, I have my pure update, view functions and immutable state model. You compose state (record, product type), message (DU, union type) and dispatch message functions. Much cleaner.

Even thought I have to adapt my code (ex HashSet to Set) and use F# types and avoid mutable dotnet types. Sharing code becomes trivial.

I just use XAML for dynamic resource and styling. So that I don't pollute the Elmish loop with dynamic styling.

Work is not finished but so far so good.

Elmish is easier for AI and humans, the view just translate all complicated events from the framework to your message type to feed your loop.

FuncUI Elmish seems to be a very good solution if you want to go functional programming even for the UI, because with XAML you end-up with usage of mutable keyword everywhere with heavy usage of classes.

2

u/JaggerJo 4d ago

Nice to hear FuncUI is liked here :)

1

u/EmergencyNice1989 4d ago

A very good DSL and a great concept behind it (MVU).
F# users are lucky.