它试图为Xamarin.Forms制作一个Xamarin.Forms,但一直受到FS2024错误的困扰。
`F#
type MainPage = Moonmile.XamarinFormsTypeProvider.XAML<"MainPage.xaml">
// made btn1 and text1 propertis
type MainPageEx(target:MainPage) =
let mutable count = 0
do
// When set event to btn.Clicked, happen FS2024 error.
// If this event is comment out, it success build.
target.btn1.Clicked.Add( fun e ->
count <- count + 1
target.btn1.Text <- "Clicked " + count.ToString())
// Property is success
member this.CurrentPage
with get() = target.CurrentPage当您指的是属性、生成和操作时,通常可以。但是Xamarin.Forms的内部类如Button.Clicked,如果您试图访问它,那就是构建错误。
错误https://github.com/moonmile/SimpleEventTypeProvider的示例代码
为XamarinFormsTypeProvider github.com/moonmile/XamarinFormsTypeProvider编写代码
也许,我怀疑不一致,并发生在生成本地TypeProvider和Xamrin.Forms.Core的部分PCL。
F# Compiler for F# 3.1 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License my error!!!
isMscorlib: true
name: "System.Runtime"
PrimaryAssembly.DotNetCore.Name: "System.Runtime"
PrimaryAssembly.Mscorlib.Name: "mscorlib"
parameter error FS2024: Static linking may not use assembly that targets different profile.它是为了正确地操作它们的属性,也许也是为了MVVM。如果可能的话,我试图实现一种分配给Button.Clicked事件的方法,如代码隐藏类建筑物中所示。
会有解决办法吗?
在WPF中的XAML的例子中,这看起来是如何工作良好的。github.com/fsprojects/FsXaml
发布于 2014-08-07 07:42:49
这个答案不一定是正确的,但它至少会帮助你朝着正确的方向前进。
首先要做的是确保您已经安装了最新的Visual工具构建,因为它添加了与F#配置文件兼容的FSharp.Core (您可以在这里找到它:(https://visualfsharp.codeplex.com/)。安装该文件后,您将希望引用Profile78或Profile259 FSharp.Core.dll (在我的计算机上,它们分别位于:"C:\Program (x86)\Reference Profile78和C:\Program (x86)\Reference Assemblies\Microsoft\FSharp.NETPortable\2.3.5.1“”)。
一旦安装了该程序,接下来要做的就是确保您的PCL项目的项目文件中有以下内容(这告诉MSBuild / xBuild,这些项目是PCL库,它们是F#项目):
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{F2A71F9B-5D33-465A-A702-920D77279786}</ProjectTypeGuids>一旦完成,您将需要选择Profile78或Profile259 (我推荐78,因为当前的Xamarin.Forms nuget包不支持259号)。
一旦完成,您应该能够构建和运行,它应该消除错误。
发布于 2014-08-08 01:21:54
谢谢你的提问。
Meybe在构建TypeProvider时,F#编译器使用mscorlib中的类。当解析btn1.clickedEvent的类型时,F#编译器在System.Runtime中使用类型。我认为这是不可能在构建时解决的。
尝试,如果使用反射附加单击事件,它已经在Android上成功地移动了。我似乎认为,如果我只使用mscorlib和System.Rutime中的shard类,我就不能生成FS2024错误。
type MainPage = Moonmile.XamarinFormsTypeProvider.XAML<"MainPage.xaml">
type MainPageEx() as this =
inherit BindObject<MainPage>(new MainPage())
// Add handlder by reflection
let AddHandler(target:obj, eventName:string, eventMethod: obj*obj -> unit ) =
let hdr = Action<obj,obj>( fun s e -> eventMethod(s,e))
let ei = target.GetType().GetRuntimeEvent(eventName)
let dt = ei.AddMethod.GetParameters().[0].ParameterType
let handler = new Action<obj,obj>(fun s e -> hdr.Invoke( s, new EventArgs() ))
let handlerInvoke = handler.GetType().GetRuntimeMethod("Invoke", [|typeof<obj>; typeof<Type[]>|])
let dele = handlerInvoke.CreateDelegate( dt, handler )
let add = new Func<Delegate, EventRegistrationToken> ( fun t ->
let para = ei.AddMethod.GetParameters()
let ret = ei.AddMethod.Invoke( target, [|t|])
if ret <> null then
ret :?> EventRegistrationToken
else
new EventRegistrationToken()
)
let remove = new Action<EventRegistrationToken>( fun t -> ei.RemoveMethod.Invoke(target, [|t|]) |> ignore )
// WindowsRuntimeMarshal.AddEventHandler<Delegate>(add, remove, dele)
add.Invoke( dele ) |> ignore
()
let mutable count = 0
do
(* // build error
target.btn1.Clicked.Add( fun e ->
count <- count + 1
target.btn1.Text <- "Clicked " + count.ToString())
*)
// add handler by reflection
AddHandler( base.Target.btn1, "Clicked", this.ButtonClick )
()
member this.CurrentPage
with get() = this.Target.CurrentPage
member this.ButtonClick(s,e) =
count <- count + 1
base.Target.text1.Text <- "clicked " + count.ToString()https://stackoverflow.com/questions/25175031
复制相似问题