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,Heigh开发者_JS百科t=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:
graph.fsx(18,46): error FS0039: The type 'DataGrid' is not defined.
but when i put the mouse cursor over "System.Windows.Controls.DataGrid()", there is a pop-up window showing the definition of datagrid.
So what did i miss? How to use datagrid in F#.
When you reference the PresentationFramework assembly without specifying a version fsi will load the 3.0 version, which does not include the DataGrid. To reference the 4.0 version you can either use the fully qualified name:
#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"
From MSDN:
Namespace: System.Windows.Controls
Assembly: System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)
You need to reference the correct assembly:
#r "System.Windows.Controls.Data"
I'm not sure what the cause of this in F# 2.0, but the issue seems to be resolved in F# 3.0
精彩评论