【问题标题】:F# can't use datagrid in WPF of .net in interactive wayF#不能以交互方式在.net的WPF中使用数据网格
【发布时间】:2012-04-14 01:03:01
【问题描述】:

我的脚本如下:

#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# 中使用数据网格。

【问题讨论】:

    标签: f# f#-interactive


    【解决方案1】:

    当您在未指定版本的情况下引用 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"   
    

    【讨论】:

      【解决方案2】:

      来自MSDN

      命名空间:System.Windows.Controls

      组装: System.Windows.Controls.Data(在 System.Windows.Controls.Data.dll)

      您需要引用正确的程序集:

      #r "System.Windows.Controls.Data"
      

      【讨论】:

      • 对不起,我的意思是我想在 .net 4 中使用 datagrid,而不是在 silverlight 中使用,但无论如何谢谢。
      【解决方案3】:

      我不确定在 F# 2.0 中这是什么原因,但该问题似乎在 F# 3.0 中得到解决

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-07-13
        • 1970-01-01
        • 1970-01-01
        • 2011-05-15
        • 2023-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多