Silverlight XAML BUG [英] Silverlight XAML BUG
问题描述
为什么如果我将其放入 Silverlight 下使用的 xaml 字典中,编译器会发现错误.
Why if I put this into a xaml dictionary used under Silverlight the compiler founds an error.
<Color x:Key="colorBackDark" A="255" R="150" G="170" B="190" />
在 WPF XAML 中一切正常.
In WPF XAML everything is OK.
顺便说一句,无论使用什么 Silverlight 版本,都会出现错误.
BTW the error is present no matter of the silverlight version used.
看起来这是某种解析器错误.
It looks like that is some kind of parser error.
推荐答案
我假设您遇到的错误类似于以下内容:
I assume the error you're getting is something like the following:
无法从文本255"创建System.Byte"
Failed to create a 'System.Byte' from the text '255'
Silverlight 中的 XAML 解析器只知道如何处理 double
s、int
s 和 bool
s.Color
结构体中的A
、R
、G
和B
属性都是byte
s,Silverlight XAML 解析器不知道如何处理.另一方面,WPF 中的 XAML 解析器确实知道如何处理这些值,所以这就是您在 WPF 中没有收到错误的原因.
The XAML parser in Silverlight only knows how to handle double
s, int
s and bool
s. The properties A
, R
, G
and B
in the Color
struct are all byte
s, which the Silverlight XAML parser doesn't know how to handle. The XAML parser in WPF, on the other hand, does know how to handle these values, so that's why you're not getting an error in WPF.
MSDNColor
结构体 的文档列出了在 Silverlight 的 XAML 中创建 Color
值的多种方法.
The MSDN documentation for the Color
struct lists a number of ways to create a Color
value in XAML in Silverlight.
一个类似问题不久前有人问到为什么 float
也不能在 Silverlight 的 XAML 中使用.
A similar question was asked a while ago about why float
s can't be used in XAML in Silverlight either.
这篇关于Silverlight XAML BUG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!