F#FsXaml:哪些控件支持哪些事件?

时间:2019-07-02 00:50:41

标签: wpf xaml f# fsxaml

<Button Click="MyClickMethod" />工作正常; XAML类型提供程序会将MyClickMethod公开为隐藏代码中的虚拟方法。

另一方面,override this.MyDoubleClickMethod (_, _)得到了<ListBox MouseDoubleClick="MyDoubleClickMethod" />的红色底线,当然我的程序无法编译。

如果不支持ListBox事件,那么在我为应用程序编码三天之前,知道这一点肯定会很高兴。 FsXaml是否在任何地方都有完整的文档记录(我并不是说源代码)?我的问题通常被接受的解决方法是什么?

编辑::这是我的代码文件(减去AssemblyInfo.fsApp.*样板),按解决方案资源管理器顺序:

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 个答案:

没有答案