iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
💧

Drag and Drop Stopped Working After Updating Avalonia.FuncUI to 1.5.2!

に公開

This article is for the 3rd day of the F# Advent Calendar 2025.

Symptoms

To accept files via drag-and-drop, I had written the following code:

let dropArea dispatch =
    TextBlock.create [
        TextBlock.text "Drop files here"
        DragDrop.allowDrop true
        DragDrop.onDrop (fun e -> Msg.Dropped e |> dispatch)
    ]

However, when I updated Avalonia.FuncUI from version 1.5.1 to 1.5.2, it stopped working.

The value, constructor, namespace, or type 'allowDrop' is not defined.
The value, constructor, namespace, or type 'onDrop' is not defined.

Before even worrying about whether it works, it won't even build. This is a problem.

Investigation of the Cause

Looking back through the FuncUI commit logs:

https://github.com/fsprojects/Avalonia.FuncUI/commit/46d44d821093e56da16e114386c4cea02faaf504

    open Avalonia.FuncUI.Builder
    open Avalonia.FuncUI.Types
    
-   type DragDrop with
+   type Control with
    
        static member onDragEnter<'t when 't :> Control> (func: DragEventArgs -> unit, ?subPatchOptions) =
            AttrBuilder<'t>.CreateSubscription<DragEventArgs>

It appears that it has been moved under the Control type.

Code Fixes

By rewriting it as follows, it works correctly now.

let dropArea dispatch =
    TextBlock.create [
        TextBlock.text "Drop files here"
-       DragDrop.allowDrop true
+       Control.allowDrop true
-       DragDrop.onDrop (fun e -> Msg.Dropped e |> dispatch)
+       Control.onDrop (fun e -> Msg.Dropped e |> dispatch)
    ]

Side Story

Although I reached the changes in FuncUI quickly in this article, in reality, I didn't figure it out right away. I asked ChatGPT, and it started talking about Behaviors, nearly leading me into a maze. I need to make sure I get into the habit of checking the source code before searching on Google or asking AI...

Discussion