[英]F# can't use datagrid in WPF of .net in interactive way
My script is below: 我的脚本如下:
#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()
Initialize window is OK, but when i initialize a datagrid , there is a error: 初始化窗口没问题,但是当我初始化datagrid时,出现错误:
graph.fsx(18,46): error FS0039: The type 'DataGrid' is not defined. graph.fsx(18,46):错误FS0039:未定义类型'DataGrid'。
but when i put the mouse cursor over "System.Windows.Controls.DataGrid()", there is a pop-up window showing the definition of datagrid. 但是,当我将鼠标光标放在“ System.Windows.Controls.DataGrid()”上时,会出现一个弹出窗口,显示datagrid的定义。
So what did i miss? 那我想念什么? How to use datagrid in F#. 如何在F#中使用datagrid。
When you reference the PresentationFramework assembly without specifying a version fsi will load the 3.0 version, which does not include the DataGrid. 当您引用PresentationFramework程序集而不指定版本时,fsi将加载3.0版本,该版本不包含DataGrid。 To reference the 4.0 version you can either use the fully qualified name: 要引用4.0版本,您可以使用标准名称:
#r "PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
or you could use the full path to the assembly. 或者您可以使用程序集的完整路径。 On my system this is: 在我的系统上,这是:
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PresentationFramework.dll"
Namespace: System.Windows.Controls 命名空间:System.Windows.Controls
Assembly: System.Windows.Controls.Data (in System.Windows.Controls.Data.dll) 程序集:System.Windows.Controls.Data(在System.Windows.Controls.Data.dll中)
You need to reference the correct assembly: 您需要引用正确的程序集:
#r "System.Windows.Controls.Data"
我不确定在F#2.0中导致此问题的原因是什么,但是在F#3.0中似乎可以解决该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.