繁体   English   中英

为什么我不能启动用F#编写的WPF应用程序?

[英]Why can't I launch a WPF app written in F#?

尝试构建用F#编写的WPF应用程序时收到以下警告:

程序主模块为空:运行时什么也不会发生

结果,我无法启动该应用程序。

我已验证所有AssemblyInfo.fs文件在末尾都带有“ do()”。 我也按照文件顺序进行操作。

有什么建议么?

更新

我在项目末尾添加了一个文件。

该文件具有以下代码:

module Bootstrap

open System.Windows

[<EntryPoint>]
let main args =
    System.Windows.Application.Current.Run() |> ignore;
    // Return 0. This indicates success.
    0

但是,当我尝试运行文件时,我在Application.Current上遇到了空引用异常。

我的解决方案如下所示:

在此处输入图片说明

这是一个使用FSharp.ViewModule.CoreFsXaml.Wpf包的最小工作示例:

MainWindow.xaml:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:local="clr-namespace:ViewModel;assembly=fsxamltest">
    <Window.DataContext>
        <local:MainViewModel/>
    </Window.DataContext>
</Window>

ViewModel.fs:

namespace ViewModel
open FSharp.ViewModule
type MainViewModel() as me = inherit ViewModelBase()

App.fs:

open System
type App = FsXaml.XAML<"App.xaml">
[<STAThread;EntryPoint>]
let main _ = App().Root.Run()

App.xaml:

<Application
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="MainWindow.xaml"/>

如果这样做不起作用,请向我们显示完整代码或创建MCVE

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM