<Button Click="MyClickMethod" />
工作正常; XAML 类型提供程序MyClickMethod
在代码隐藏中公开为虚拟方法。
另一方面,override this.MyDoubleClickMethod (_, _)
得到漂亮的红色下划线<ListBox MouseDoubleClick="MyDoubleClickMethod" />
,当然我的程序无法编译。
如果ListBox
不支持事件,那么在我用三天时间编写应用程序之前知道这一点肯定会很高兴。FsXaml 是否在任何地方都有很好的文档记录(我不是指源代码)?我的问题普遍接受的解决方法是什么?
编辑:这是我的代码文件(减号AssemblyInfo.fs
和App.*
样板文件),按解决方案资源管理器顺序:
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>