gpt4 book ai didi

.net - F# 将 TextBlock 向上转换为 UIElement

转载 作者:行者123 更新时间:2023-12-01 11:58:50 24 4
gpt4 key购买 nike

有什么问题:

let (x:UIElement) = upcast new TextBlock()

错误是:此处需要类型“System.ComponentModel.ISupportInitialize”,但该类型不可用。您必须添加对程序集“System, Version=4.0.0....”的引用

TextBlock UIElement 的子类型...

请注意,按照错误消息所说的操作确实可以解决问题,但为什么有必要执行像向上转换这样基本的操作?

最佳答案

正如 lasseespeholt 在他的(现已删除?)回答中提到的,您的代码没有任何问题,您只需添加对 System.dll 的引用作为错误信息提示。

但是这是怎么回事?您在该特定行收到错误消息,因为它是编译器遇到 System.dll 库(一个接口(interface) ISupportInitialize,它是由 TextBlock 实现)并意识到它需要对库的引用才能理解类型。

获得相同错误信息的另一种方法是这样写:

let x = new TextBlock() 
x. // If you get IntelliSense here, you'll see just '<Note>'
// with the same error message as the one you're getting

在这种情况下,IntelliSense 需要查看类型(以便它可以填充成员完成)。

关于.net - F# 将 TextBlock 向上转换为 UIElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3537874/

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