用F#编写的WPF转换器无法识别

时间:2014-07-14 06:54:02

标签: wpf f# ivalueconverter

我在F#中写了以下转换器

namespace My.FSharpLibrary

open System
open System.Collections.Generic
open System.Linq
open System.Text
open System.Threading.Tasks
open System.Globalization
open System.Windows.Data

type ValueCompareConverter() =
    member val ReferenceValue = Unchecked.defaultof<float> with get,set
    interface IValueConverter with
        member this.Convert(value,targetType,parameter,culture) =
            let f = float (value.ToString())

            match parameter.ToString() with
                | "LessThan" -> f < this.ReferenceValue :> obj
                | "GreaterThan" -> f > this.ReferenceValue :> obj
                | _ -> failwith "Invalid Converter parameter"; false :> obj

        member this.ConvertBack(value,targetType,parameter,culture) =
            failwith "Not implemented"

我可以在Object Browser中看到这个转换器,但是在我的C#WPF项目中添加对我的库的引用并添加以下xaml代码

... xmlns:helpers="clr-namespace:My.FSharpLibrary" ...

...

 <helpers:ValueCompareConverter ReferenceValue="0.0" x:Key="compareToZeroConverter"  />

我收到以下错误

  

错误140名称“ValueCompareConverter”在名称空间“clr-namespace:My.FSharpLibrary”中不存在。

有任何线索吗?

1 个答案:

答案 0 :(得分:2)

杜!

我必须将assembly=My.FSharpLibrary添加到命名空间定义

 <Window xmlns:helpers="clr-namespace:My.FSharpLibrary;assembly=My.FSharpLibrary"  />