x:TypeArguments 中的可空类型 [英] Nullable type in x:TypeArguments

查看:25
本文介绍了x:TypeArguments 中的可空类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to pass nullable type to XAML generic type arguments(x:TypeArguments) ?

我有:

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

我需要 Int32 可以为空.. 像

I need Int32 to be nullable.. something like

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

这似乎是无效的 XML/XAML.

Which seems to be invalid XML/XAML.

我也尝试将其声明为 sys:Nullabe&lt;sys:Int32&gt; 并且错误是:

I tried to declare it as sys:Nullabe&lt;sys:Int32&gt; too and the error is:

'sys.Nullable' 不是泛型参数的有效类型名称引用

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

推荐答案

不,很遗憾,这是不可能的.您需要创建一个中间类来解决这个问题(我已经尝试了所有可能的方法,但都不起作用).

No, that is not possible unfortunately. You need to create an intermediate class to overcome this problem (I have tried all possible ways, it just doesn't work).

<base:NullableInt32ControlBase ... >

其中 NullableControlBase 是中间类:

public class NullableInt32ControlBase : ControlBase<int?>
{ }

这篇关于x:TypeArguments 中的可空类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆