【问题标题】:This expression was expected to have type 'obj' but here has type 'string'此表达式应为“obj”类型,但此处为“字符串”类型
【发布时间】:2019-02-04 22:39:47
【问题描述】:

下面的代码有一个类型错误,比如“这个表达式应该有类型'obj',但这里有类型'string'”

    let fiveDaysForecast (model: CityForecast) = 
        let fiveDays = model.Days |> List.truncate 5
        let city = if model.Country |> String.IsNullOrWhiteSpace then model.City else sprintf "%s, %s" model.City model.Country 
        View.StackLayout(padding = 20.0, verticalOptions = LayoutOptions.FillAndExpand,
            children = [ 
                View.Label(text=city.ToUpper(), textColor=Color.Beige, backgroundColor=Color.FromHex("#0F4D8FAC"), fontSize=40, fontAttributes=FontAttributes.Bold, horizontalTextAlignment=TextAlignment.Center)
                empty 20.
                View.Grid(
                    rowdefs=["*"],
                    coldefs=[ for _ in fiveDays -> "*" ],
                    children = (fiveDays |> List.mapi (day 0) ) )
                ])

由于"*"coldefs=[ for _ in fiveDays -> "*" ], 这行代码出错

我应该如何解决它?

【问题讨论】:

  • 是 WPF 还是别的什么? coldefs的类型是什么?
  • Sooo... Xamarin 还是 WPF?另外:coldefs的类型是什么?
  • @FyodorSoikin xamarin,字符串
  • coldefs 的值为string?您确定它不是列表或数组或类似的东西吗?
  • @FyodorSoikin 很抱歉,它是数组

标签: f#


【解决方案1】:

根据 Fabulous Guide (https://fsprojects.github.io/Fabulous/views-perf.html),您需要将列表元素装箱:

coldefs=[ for _ in fiveDays -> box "*" ]

【讨论】:

  • tnx 修复了这么多,通过 coldefs=[ for i in FiveDays -> box "*" ]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多