我的脚本如下:
#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()
初始化窗口没问题,但是当我初始化数据网格时,出现错误:
graph.fsx(18,46):错误FS0039:未定义“DataGrid”类型。
但当我把鼠标光标放在“System.Windows.Controls.DataGrid()”上时,那里 是一个弹出窗口,显示datagrid的定义。
那我错过了什么?如何在F#中使用datagrid。
答案 0 :(得分:0)
来自MSDN:
命名空间:System.Windows.Controls
大会: System.Windows.Controls.Data(in System.Windows.Controls.Data.dll)
您需要引用正确的程序集:
#r "System.Windows.Controls.Data"
答案 1 :(得分:0)
我不确定F#2.0中的原因是什么,但问题似乎在F#3.0中得到解决
答案 2 :(得分:0)
当您引用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"