我正在尝试用F#,WPF和FsXaml创建一个按钮Hello World应用程序。我开始遵循这个指南:
https://www.c-sharpcorner.com/article/create-wpf-application-with-f-sharp-and-fsxaml/
当我只是在xaml上加载程序并进行编译时,一切都很正常,但是我还没有设法通过按下按钮来调用函数,在他解释如何调用函数之前,指南就结束了。
我已经看到了许多不同的方法,但还没有一种方法对我有效(而且许多指南都已经有几年的历史了,所以从那以后框架内部发生了很多事情)。一旦我理解了在使用FsXaml时x.xaml和x.xaml.fs之间的逻辑,就能有一个有效的(且简单的)起点开始构建,那就太好了。
我在MainWindow.xaml上的按钮:
<Button x:Name="submitButton" Content="Send" Click="submitButton_Click"/>我在MainWindow.xaml的window -section中也有这个:
xmlns:local="clr-namespace:Views;assembly=GUItemplate"我的MainWindow.xaml.fs:
namespace GUItemplate
open FsXaml
open System.Windows
type MainWindowBase = XAML<"MainWindow.xaml">
type MainWindow() =
inherit MainWindowBase()
override this.submitButton_Click (sender: obj, e: RoutedEventArgs) =
MessageBox.Show("Hello world!")
|> ignore我目前得到的错误:
System.Windows.Markup.XamlParseException
HResult=0x80131501
Message='Failed to create a 'Click' from the text 'submitButton_Click'.' Line number '29' and line position '101'.
Source=PresentationFramework
Inner Exception 1:
ArgumentException: Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.发布于 2019-01-10 23:54:01
这就是我在VS 2017中的工作方式,对我来说,它是有效的。我添加了UIAutomationTypes引用并安装了NuGet FsXaml.Wpf。
open System
open System.Windows
open FsXaml
type MainWindowBase = XAML<"MainWindow.xaml">
type MainWindow() =
inherit MainWindowBase()
override this.submitButton_Click (sender: obj, e: RoutedEventArgs) =
MessageBox.Show("Hello world!")
|> ignore
[<EntryPoint;STAThread>]
let application = new Application() in
let mainWindow = new MainWindow() in
application.Run(mainWindow) |> ignore https://stackoverflow.com/questions/54111774
复制相似问题