System:Char 类型的异常
我正在尝试在我的 xaml
资源中创建可重用的 System:Char
值。
我有:
xmlns:s="clr-namespace:System;assembly=mscorlib"
然后:
<s:Char x:Key="MaskPromptChar">#</s:Char>
我得到一个异常:
The type 'Char' was not found. [Line: 8 Position: 44]
但是...我也有:
<s:Double x:Key="DefaultControlWidth">200</s:Double>
并且...
<s:String x:Key="ApplicationTitle">My Title</s:String>
String
和 Double
都工作正常。
想法??
I am trying to create a reusable System:Char
value in my xaml
resources.
I have:
xmlns:s="clr-namespace:System;assembly=mscorlib"
Then:
<s:Char x:Key="MaskPromptChar">#</s:Char>
I get an exception:
The type 'Char' was not found. [Line: 8 Position: 44]
But... I also have:
<s:Double x:Key="DefaultControlWidth">200</s:Double>
And...
<s:String x:Key="ApplicationTitle">My Title</s:String>
Both String
and Double
work fine.
Ideas??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这段代码在 Silverlight 和 WPF 中都适用。
您试图将字符分配给什么属性?
This code works for me in both Silverlight and WPF.
What property are you trying to assign the char to?
我的猜测是 Char 是一个结构< /a>,而不是一个对象,您真正看到的是表示 Unicode 的 16 位整数值的装箱。我倾向于将 XAML 视为对象的专门化序列化,如果 Char 实际上是一个 struct,这个模型可能会崩溃。
您可能需要考虑硬着头皮使用长度为 1 的字符串。
更新:我同意gmcalab的可靠推理,并在此基础上使用mscorlib的命名空间和相应的字符资源进行了实验。 它工作顺利。 (我们现在正在考虑命名空间或库冲突问题吗?)
My guess is that Char is a structure, rather than an object, and what's you're really looking at is boxing of a 16-bit integer value representing Unicode. I tend to look at XAML as a specialization serialization of objects, and if Char is actually a struct, this model may break down.
You might want to consider biting the bullet and using a String of length one instead.
UPDATE: I agree with gmcalab's solid line of reasoning, and based on that conducted an experiment using a namespace to mscorlib and the corresponding character resource. It worked without a hitch. (Are we now looking at a namespace or library collision problem?)