是否可以将可空类型传递给 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/