gpt4 book ai didi

c# - x :TypeArguments 中的可空类型

转载 作者:太空狗 更新时间:2023-10-30 01:33:16 25 4
gpt4 key购买 nike

是否可以将可空类型传递给 XAML 泛型类型参数 (x:TypeArguments)?

我有:

 <base:ControlBase
x:TypeArguments="sys:Int32"
...

我需要 Int32 可以为 null.. 类似

<base:ControlBase
x:TypeArguments="sys:Nullable<sys:Int32>"
...

这似乎是无效的 XML/XAML。

我也尝试将其声明为 sys:Nullabe<sys:Int32>,但错误是:

'sys.Nullable' is not a valid type name reference for the generic argument

最佳答案

不,不幸的是,这是不可能的。你需要创建一个中间类来克服这个问题(我已经尝试了所有可能的方法,它就是不起作用)。

<base:NullableInt32ControlBase ... >

其中 NullableControlBase 是中间类:

public class NullableInt32ControlBase : ControlBase<int?>
{ }

关于c# - x :TypeArguments 中的可空类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34431590/

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