Skip to content

Conversation

CoolCoderSuper
Copy link
Contributor

@CoolCoderSuper CoolCoderSuper commented Aug 26, 2025

@JaggerJo
I was taking another look at this and dug a bit deeper into how the render process works and got something working.

    override this.Initialize() =
        let menu = NativeMenu.create [
                    NativeMenu.items [
                        NativeMenuItem.create [
                            NativeMenuItem.header "File"
                            NativeMenuItem.isChecked true
                            NativeMenuItem.isEnabled false
                        ]
                    ]
                ]
        let tray =
            TrayIcon.create [
                TrayIcon.toolTipText "Control Catalog"
                TrayIcon.menu menu
            ]
        let icon = Avalonia.FuncUI.VirtualDom.VirtualDom.createObject tray :?> TrayIcon
        let icons  = TrayIcons()
        icons.Add(icon)
        TrayIcon.SetIcons(this, icons)

I still need to make sure I'm not missing any properties in the bindings.

Image

I implemented an additional function in the VirtualDom module to render an AvaloniaObject instead of a Control.

This approach obviously isn't stateful since it only renders once.
I kinda feel like we should maybe come up with some better apis for managing the App object.
But open to your thoughts.

Fixes #427

open Avalonia

module rec VirtualDom =
let createObject (view: IView) : AvaloniaObject =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this generic?

IView<'view> -> 'view

@JaggerJo
Copy link
Member

JaggerJo commented Aug 26, 2025

@CoolCoderSuper nice progress!

The Virtual DOM was changed in many places to work with AvaloniaObject instead of Control. We are now able to diff and patch AvaloniaObjects. That change was required to support text runs IIRC.

I agree, we should do something similar to what Swift UI does. Maybe using a component like concept - App.create instead of Component.create

@main
struct FSApp: App {
  var body: some Scene {
    WindowGroup {
      ContentView()
    }
  }
}

@JaggerJo JaggerJo changed the base branch from master to window-component-experiment October 12, 2025 14:27
@JaggerJo JaggerJo merged commit 6ee5bf5 into fsprojects:window-component-experiment Oct 12, 2025
@JaggerJo
Copy link
Member

@CoolCoderSuper created a new branch to experiment with the additional changes. Realized that we can merge this to master directly... created a new PR: #477

Thanks for the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App.axaml replacement

2 participants