[英]F# can't use datagrid in WPF of .net in interactive way
我的脚本如下:
#light
#r "WindowsBase"
#r "PresentationCore"
#r "PresentationFramework"
open System
open System.Windows
open System.Windows.Controls
let window = new System.Windows.Window(Name="Test",Width=500.0,Height=500.0)
window.Visibility <- Visibility.Visible
window.Show()
let mutable wp = new System.Windows.Controls.DataGrid()
初始化窗口没问题,但是当我初始化datagrid时,出现错误:
graph.fsx(18,46):错误FS0039:未定义类型'DataGrid'。
但是,当我将鼠标光标放在“ System.Windows.Controls.DataGrid()”上时,会出现一个弹出窗口,显示datagrid的定义。
那我想念什么? 如何在F#中使用datagrid。
当您引用PresentationFramework程序集而不指定版本时,fsi将加载3.0版本,该版本不包含DataGrid。 要引用4.0版本,您可以使用标准名称:
#r "PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
或者您可以使用程序集的完整路径。 在我的系统上,这是:
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PresentationFramework.dll"
从MSDN :
命名空间:System.Windows.Controls
程序集:System.Windows.Controls.Data(在System.Windows.Controls.Data.dll中)
您需要引用正确的程序集:
#r "System.Windows.Controls.Data"
我不确定在F#2.0中导致此问题的原因是什么,但是在F#3.0中似乎可以解决该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.