F#/WPF event binding

后端 未结 4 1618
青春惊慌失措
青春惊慌失措 2020-12-29 16:48

I am wandering if there is a way of hooking an event defined in XAML to a F# function of member ? Of course, I could do it diagrammatically but it is kind of inconvenient. <

4条回答
  •  孤城傲影
    2020-12-29 17:27

    This is now supported in the newer versions of FsXaml, though it works slightly differently than it does in C#.

    Using FsXaml, you can define your Xaml and specify your event handler. For example, in a window named "MyWindow", you can do:

    In your "code behind" file, you would handle this like so:

    type MyWindowBase = XAML<"MyWindow.xaml">
    type MyWindow () =
        inherit MyWindowBase
    
        override this.button1_Click (_,_) = () // Handle event here
    

提交回复
热议问题