Silverlight文本元素―高级修饰
Silverlight为Brush提供了几个派生类:SolidColorBrush;ImageBrush;LinearGradientBrush;RadialGradientBrush;VideoBrush;它们表示单色画刷,图片画刷,线性渐变画刷,放射性渐变画刷,视频画刷。下面我们通过代码来说明一下这几个画刷的应用。
<
StackPanel
x
:
Name
="LayoutRoot"
Background
="AliceBlue">
<!―
线性渐变画刷
-->
<
TextBlock
FontSize
="20"
FontWeight
="Bold">
线性渐变画刷
<
TextBlock.Foreground
>
<
GradientStop
Color
="Red"
Offset
="0.0"/>
<
GradientStop
Color
="AliceBlue"
Offset="0.4"/>
<
GradientStop
Color
="Yellow"
Offset="0.8"/>
<
GradientStop
Color
="Black"
Offset="1.1"/>
</
TextBlock.Foreground
>
</
TextBlock
>
<
TextBlock
FontSize
="20"
FontWeight
="Bold">
<
TextBlock.Foreground
>
</
TextBlock.Foreground
>
</
TextBlock
>
<!--
放射性画刷
-->
<
TextBlock
FontSize
="20"
FontWeight
="Bold">
放射性画刷
<
TextBlock.Foreground
>
<
GradientStop
Color
="Red"
Offset
="0.0"/>
<
GradientStop
Color
="Yellow"
Offset="0.4"/>
<
GradientStop
Color
="AliceBlue"
Offset="0.8"/>
<
GradientStop
Color
="Black"
Offset="1.1"/>
</
TextBlock.Foreground
>
</
TextBlock
>
</
StackPanel
>
演示效果如图:
那么我们先来看看有那些派生类和这些派生类能够实现的功能吧!
1)RotateTransform:旋转变形,可以控制文本的旋转角度;
2)ScaleTransform:缩放变形,可以控制文本的缩放比例;
4)TranslateTransform:移动变形,控制文本相对于原始位置的距离;
5)TransformGroup:组合变形,组合多个变形;
6)MatrixTransform:矩形变形,二维空间中任意控制文本或坐标系统。
<!--普通文本-->
<TextBlock Text="Rotate text" FontSize="20"/>
<!--旋转变形文本-->
<TextBlock Text="Rotate text" FontSize="20">
<TextBlock.RenderTransform>
<RotateTransform Angle="45" CenterX="30" CenterY="30"/>
</TextBlock.RenderTransform>
</TextBlock>
缩放变形可以从宽度和高度两个方向来控制文本的大小,代码如下:
<!--普通文本-->
<TextBlock Text="Scaled text" FontSize="20"/>
<!--增大文本宽度-->
<TextBlock Text="Scaled text" FontSize="20">
<TextBlock.RenderTransform>
<ScaleTransform ScaleX="3"/>
</TextBlock.RenderTransform>
</TextBlock>
<!--增大文本高度-->
<TextBlock Text="Scaled text" FontSize="20">
<TextBlock.RenderTransform>
<ScaleTransform ScaleY="2"/>
</TextBlock.RenderTransform>
</TextBlock>
我们可以通过倾斜变形来设置文本在垂直方向和水平方形的倾斜,代码如下:
<!--普通文本-->
<TextBlock Text="Scaled text" FontSize="20"/>
<!--文本水平倾斜-->
<TextBlock Text="Scaled text" FontSize="20">
<TextBlock.RenderTransform>
<SkewTransform AngleX="45"/>
</TextBlock.RenderTransform>
</TextBlock>
<!--文本垂直倾斜-->
<TextBlock Text="Scaled text" FontSize="20">
<TextBlock.RenderTransform>
<SkewTransform AngleY="30"/>
</TextBlock.RenderTransform>
</TextBlock>
移动变形可以在水平或垂直方向把文本从原始位置移动到新位置。代码如下:
<Canvas x:Name="LayoutRoot" Background="AliceBlue">
<!--文本移动-->
<TextBlock Text="Translated text" FontSize="50" Foreground="Gray">
<TextBlock.RenderTransform>
<TranslateTransform X="5" Y="5"/>
</TextBlock.RenderTransform>
</TextBlock>
<!--普通文本-->
<TextBlock Text="Translated text" FontSize="50"/>
</Canvas>
<StackPanel x:Name="LayoutRoot" Background="AliceBlue" Orientation="Horizontal">
<TextBlock textwrapping="Wrap" Width="250">
Nowadays,there usually exists a wide selection of electives for
college students to choose from. However,students have quite
different plans for their future so they always end up learning
courses based on their own ideas.
Some students may choose to learn a certain course in order to
obtain an extra certificate for their job hunting after graduation.
chances of winning in finding a good job. Others may have their
choice made just for fun. They tend to hold the idea that college
through elective courses.
As far as I’m concerned,I’m inclined to choose electives based on
both the value of the courses and the interest of my own.
<TextBlock.Clip>
<
EllipseGeometry
Center
="100,100" RadiusX="100" RadiusY="100"/>
</TextBlock.Clip>
</TextBlock>
<!--普通文本-->
<TextBlock textwrapping="Wrap" Width="250">
Nowadays,students have quite
different plans for their future so they always end up learning
courses based on their own ideas.
Some students may choose to learn a certain course in order to
obtain an extra certificate for their job hunting after graduation.
chances of winning in finding a good job. Others may have their
choice made just for fun. They tend to hold the idea that college
through elective courses.
As far as I’m concerned,I’m inclined to choose electives based on
both the value of the courses and the interest of my own.
<TextBlock.Clip>
<PathGeometry>
<Pathfigure StartPoint="0,200" IsClosed="True">
</Pathfigure>
</PathGeometry>
</TextBlock.Clip>
</TextBlock>
</StackPanel>
效果如图:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。