f# - F# 交互中的 Windows UI(UWP 或 8.1)

标签 f# uwp uwp-xaml f#-interactive

通过引用默认的 WPF DLL,使用纯代码 WPF 可以很容易地做任何你可以做的事情:

#r "PresentationCore.dll"
#r "PresentationFramework.dll"
// ...other DLLs...
#r "WindowsBase.dll"

let window = System.Windows.Window()
let panel = System.Windows.Controls.StackPanel()
let button = System.Windows.Controls.Button()
panel.Children.Add button
button.Content <- "hi"

window.Content <- panel

window.Show()

...并且您可以在窗口仍然打开时对其进行操作...
button.Click.Add (fun _ ->
    button.Content <-
        button.Content :?> string |> fun x -> (x + "!") :> obj)

...然后单击按钮查看它的工作情况。这似乎是构建 UI 组件的一种非常强大的方法。

有没有办法对 Windows.UI 命名空间/控件/UI 框架做同样的事情——在 F# 交互中加载一些程序集并动态实例化 UI 组件?

我天真地尝试引用似乎相关的文件:
#r @"C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\2.0.0.0\Windows.Foundation.UniversalApiContract.winmd"
#r @"C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.FoundationContract\2.0.0.0\Windows.Foundation.FoundationContract.winmd"

...这样做让我智能感知到 Windows.UI 命名空间。但是当我尝试实例化某些东西时:
Windows.UI.Xaml.Application()

我得到:
error FS0193: Could not load file or assembly 'file:///C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\2.0.0.0\Windows.Foundation.UniversalApiContract.winmd' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

最佳答案

我的理解是目前还没有对 UWP 的 F# 支持。
例如,参见这个新鲜 open issue .

关于f# - F# 交互中的 Windows UI(UWP 或 8.1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38343566/

相关文章:

F# - 构造嵌套类型

javascript - 在 React-native 应用程序中使用 Fable 中的 native 模块

UWP 中的 C# XML 序列化

c++ - 使用c++/WinRT Direct3D UWP Game DR模板Direct X11的错误消息

uwp - 为什么我的 UWP 应用程序(仅)在 Windows 11 下出现延迟?

c# - UWP 如何显示来自网络目录的图像

c# - 是否有 F# 语言的 ServiceStack API

F#:配管 vs. 作曲 vs. ......作曲?

c# - UWP 中的自定义 MarkupExtension

sockets - 在UWP StreamSocket中,我可以在超时的情况下读取数据并在超时后保持连接打开状态吗?