F# FsXaml: Which events are supported for which controls?

171 Views Asked by At

<Button Click="MyClickMethod" /> works fine; the XAML type provider exposes MyClickMethod as a virtual method in the code-behind.

On the other hand, override this.MyDoubleClickMethod (_, _) gets the pretty red underlining for <ListBox MouseDoubleClick="MyDoubleClickMethod" />, and of course my program fails to compile.

If ListBox events aren't supported, then it sure would have been nice to know this before I got three days into coding my application. Is FsXaml well documented anywhere (and I don't mean the source code)? What's the generally accepted work-around for my problem?

EDIT : Here are my code files (minus AssemblyInfo.fs and App.* boilerplate), in Solution Explorer order:

MainViewModel.fs:

namespace MyWpf.ViewModels

open ViewModule
open ViewModule.FSharp

type MainViewModel () as self = 
    inherit ViewModelBase ()

    let myItems = self.Factory.Backing (<@ self.MyItems @>, Array.empty)

    do
        self.MyItems <- [| "cheeseburger"; "French fries"; "chocolate shake" |]

    member this.MyItems
        with get () = lock myItems (fun () -> myItems.Value)
        and private set value = lock myItems (fun () -> myItems.Value <- value)

MainView.xaml.fs:

namespace MyWpf.Views

open System.Windows

type MainViewBase = FsXaml.XAML<"MainView.xaml">
type MainView () =
    inherit MainViewBase ()

    override this.MyDoubleClickMethod (_, _) = MessageBox.Show "click!" |> ignore

MainView.xaml:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:viewModels="clr-namespace:MyWpf.ViewModels;assembly=MyWpf">

    <UserControl.DataContext>
        <viewModels:MainViewModel />
    </UserControl.DataContext>

    <Grid>
        <ListBox
            Name="MyList"
            Width="300"
            Height="224"
            Margin="10,4,10,4"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            ItemsSource="{Binding MyItems}"
            MouseDoubleClick="MyDoubleClickMethod" />
    </Grid>
</UserControl>

MainWindow.xaml.fs:

namespace MyWpf.Windows

type MainWindow = FsXaml.XAML<"MainWindow.xaml">

MainWindow.xaml:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:views="clr-namespace:MyWpf.Views;assembly=MyWpf"
    Width="320"
    Height="240"
    ResizeMode="CanMinimize"
    WindowStartupLocation="CenterScreen">
    <Grid>
        <views:MainView />
    </Grid>
</Window>
0

There are 0 best solutions below