首页 > 文章
XAML 语法简介
- 来源-蓝色理想
- 作者-
- 发表时间-2007-08-03 15:55:14
- 查看评论
使用 Implicit Collection Syntax设置属性
有时候, 一个属性表现为一个集合, 你可以忽略集合名字,直接设置属性值。这就是implicit collection syntax.。下面的例子展示了对于LinearGradientBrush 如何忽略GradientStopCollection ,以及直接指定 GradientStop 对象。 GradientStopCollection 包含在第一个LinearGradientBrush中,,但在第二个里被忽略了。XAML
<Rectangle Width="100" Height="100"
Canvas.Left="0" Canvas.Top="30">
<Rectangle.Fill>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<!-- Here the GradientStopCollection tag is specified. -->
<GradientStopCollection>
<GradientStop Offset="0.0" Color="Red" />
<GradientStop Offset="1.0" Color="Blue" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Width="100" Height="100"
Canvas.Left="100" Canvas.Top="30">
<Rectangle.Fill>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<!-- Notice that the GradientStopCollection tag
is omitted. -->
<GradientStop Offset="0.0" Color="Red" />
<GradientStop Offset="1.0" Color="Blue" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
有时你甚至可以同时忽略集合元素标签和属性元素标签::XAML
<Rectangle Width="100" Height="100"
Canvas.Left="200" Canvas.Top="30">
<Rectangle.Fill>
<LinearGradientBrush>
<GradientStop Offset="0.0" Color="Red" />
<GradientStop Offset="1.0" Color="Blue" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
什么时候使用Attribute或Property Element Syntax设置属性
所有属性都支持attribute 或property element syntax, 一些属性支持其他方法. 设置属性所支持的方法取决于属性值所认可的对象类型。.
如果属性值是简单类型, 比如 Double, Integer,String, 这种属性只支持 attribute syntax . 下面的例子展示了如何使用 attribute syntax 设置Rectangle的Width.Width属性支持Attribute syntax,因为他的属性值是Double类型。 XAML
<Rectangle Width="100" />
是否可以使用attribute syntax取决于你使用于设置属性的对象是否支持attribute syntax.下面的例子展示了使用 attribute syntax 设置一个Rectangle的 Fill属性。在你使用SolidColorBrush去设置Fill属性的时候,它是支持attribute syntax的,因为SolidColorBrush支持attribute syntax. XAML
<Rectangle Fill="Blue" />
是否能够使用element syntax 设置属性取决于你使用的对象是否支持。如果对象支持object element syntax,属性才支持property element syntax 。下面的例子展示了使用property element syntax 设置一个Rectangle的Fill.当你使用SolidColrBrush设置Fill的时候,它是支持attribute syntax的,因为SolidColorBrush支持attribute syntax 。. XAML
<Rectangle>
<Rectangle.Fill>
<SolidColorBrush />
</Rectangle.Fill>
</Rectangle>
See Also
Silverlight Object Models
有时候, 一个属性表现为一个集合, 你可以忽略集合名字,直接设置属性值。这就是implicit collection syntax.。下面的例子展示了对于LinearGradientBrush 如何忽略GradientStopCollection ,以及直接指定 GradientStop 对象。 GradientStopCollection 包含在第一个LinearGradientBrush中,,但在第二个里被忽略了。XAML
<Rectangle Width="100" Height="100"
Canvas.Left="0" Canvas.Top="30">
<Rectangle.Fill>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<!-- Here the GradientStopCollection tag is specified. -->
<GradientStopCollection>
<GradientStop Offset="0.0" Color="Red" />
<GradientStop Offset="1.0" Color="Blue" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Width="100" Height="100"
Canvas.Left="100" Canvas.Top="30">
<Rectangle.Fill>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<!-- Notice that the GradientStopCollection tag
is omitted. -->
<GradientStop Offset="0.0" Color="Red" />
<GradientStop Offset="1.0" Color="Blue" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
有时你甚至可以同时忽略集合元素标签和属性元素标签::XAML
<Rectangle Width="100" Height="100"
Canvas.Left="200" Canvas.Top="30">
<Rectangle.Fill>
<LinearGradientBrush>
<GradientStop Offset="0.0" Color="Red" />
<GradientStop Offset="1.0" Color="Blue" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
什么时候使用Attribute或Property Element Syntax设置属性
所有属性都支持attribute 或property element syntax, 一些属性支持其他方法. 设置属性所支持的方法取决于属性值所认可的对象类型。.
如果属性值是简单类型, 比如 Double, Integer,String, 这种属性只支持 attribute syntax . 下面的例子展示了如何使用 attribute syntax 设置Rectangle的Width.Width属性支持Attribute syntax,因为他的属性值是Double类型。 XAML
<Rectangle Width="100" />
是否可以使用attribute syntax取决于你使用于设置属性的对象是否支持attribute syntax.下面的例子展示了使用 attribute syntax 设置一个Rectangle的 Fill属性。在你使用SolidColorBrush去设置Fill属性的时候,它是支持attribute syntax的,因为SolidColorBrush支持attribute syntax. XAML
<Rectangle Fill="Blue" />
是否能够使用element syntax 设置属性取决于你使用的对象是否支持。如果对象支持object element syntax,属性才支持property element syntax 。下面的例子展示了使用property element syntax 设置一个Rectangle的Fill.当你使用SolidColrBrush设置Fill的时候,它是支持attribute syntax的,因为SolidColorBrush支持attribute syntax 。. XAML
<Rectangle>
<Rectangle.Fill>
<SolidColorBrush />
</Rectangle.Fill>
</Rectangle>
See Also
Silverlight Object Models
- 内容简介
- XAML是一种陈述性语言。你可以使用XAML标记创建可视化的UI原件。 之后,你可以在一个单独的文件中使用JavasScript来操作你在XAML所声明的对象、响应一些事件。
关于编辑
- 齐家里
- 负责内容:所有工作*2就是拉 具体工作内容请参考本编辑组马尚同志的工作介绍
- 电子信箱:info@chinavisual.com
- 博客:blog.chinavisual.com
- 个人签名:我就喜欢在家里,嘿嘿






网友评论