gpt4 book ai didi

xamarin.forms - 单声道错误 : Error message when attempting to observe a newly assigned value after mutating an object member

转载 作者:行者123 更新时间:2023-12-02 11:16:16 25 4
gpt4 key购买 nike

在改变对象成员后尝试观察新分配的值时,我正在观察数据提示上的错误消息。
View 模型:
我正在尝试改变 View 模型对象的 header 成员。

let mutable header : NavBarItem option = None

member x.Header with get() = header
and set(v) = header <- v
base.NotifyPropertyChanged(<@ x.Header @>)
...
//----------------------------------
// THE FOLLOWING ERRORS
//----------------------------------
member x.LoadAsync(panelId:PanelId) =

let items = seq [NavBarItem() :> UITemplate]

let result = items |> Seq.map (fun v -> v :?> NavBarItem)
|> Seq.tryHead // Error recovering value

x.Header <- result
错误:
这是我将光标悬停在 x.Header 上后的错误:

Incorrect number or types of arguments Parameter name: arguments


enter image description here
这是一个 bug report我在研究错误消息后观察到的。
更新:
我尝试序列化我确实有权访问的对象序列,以便我可以反序列化 json 并访问单个项目。
这也失败了:
   let temp = seq [NavBarItem() :> UITemplate] |> filterToNavBarItems 
|> Seq.cast<NavBarItem>

let json = JsonConvert.SerializeObject(temp)
let items = JsonConvert.DeserializeObject<NavBarItem seq>(json)
let item = items |> Seq.tryHead

x.Header <- item // Error recovering value
杰森:
[{"MeasureId":"some_navbar_id","Header":"Dashboard","Subheader":"Trauma Alerting","EmblemLabel":"","IsEmblemAttached":false,"EmblemBGColor":"","EmblemFGColor":""}]
附录:
type UITemplate =
abstract member ToString : unit -> string
abstract member OrderIndex : int with get, set

type NavBarItem() =

inherit ViewModelBase()

let mutable header = ""

interface UITemplate with
member x.ToString() = "NavBarItem"
member val OrderIndex = -1 with get,set

member x.Header with get() = header
and set(v) = header <- v
base.NotifyPropertyChanged(<@ x.Header @>)


type ViewModelBase () =

let propertyChanged = Event<PropertyChangedEventHandler,PropertyChangedEventArgs>()

let getPropertyName = function
| PropertyGet(_,pi,_) -> pi.Name
| _ -> invalidOp "Expecting property getter expression"

interface INotifyPropertyChanged with

[<CLIEvent>]
member this.PropertyChanged = propertyChanged.Publish

member this.NotifyPropertyChanged propertyName =
propertyChanged.Trigger(this,PropertyChangedEventArgs(propertyName))

member this.NotifyPropertyChanged quotation =
quotation |> getPropertyName |> this.NotifyPropertyChanged

最佳答案

很难回答你的问题,因为代码不能真正按原样编译。这使得很难看出错误在哪里,因为它可能与您的代码段中未显示的内容有关。
我尝试通过尽可能多地删除来编译代码。我最终得到了以下结果,但这很好用:

type ViewModelBase() = 
member x.NotifyPropertyChanged(a:Microsoft.FSharp.Quotations.Expr<'a>) = ()

type NavBarItem() =
inherit ViewModelBase()
let mutable header : NavBarItem option = None
member x.Header
with get() = header
and set(v) =
header <- v
base.NotifyPropertyChanged(<@ x.Header @>)
member x.LoadAsync(panelId:int) = async {
let result = None
x.Header <- result }
如果您可以扩展这个最小样本以使其显示错误,那么我相信人们将能够提供帮助。

关于xamarin.forms - 单声道错误 : Error message when attempting to observe a newly assigned value after mutating an object member,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62583282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com