|
|
Questions and answers for Graphics and Multimedia Rendering Graphics.
|
26. Graphics and Multimedia Rendering Graphics
|
| 26.1
How can I create a combine hard and soft shadow ?
|
| 26.2
How can I use a DoubleAnimation to rotate the textblock ?
|
| 26.3
What is the order in which the controls are rendered ?
|
| 26.4
How do I enumerate child objects in a visual tree ?
|
| 26.5
How rendering in WPF differs from WIN32 applications?
|
26.1 How can I create a combine hard and soft shadow ?
|
|
This can be done as follows.
|
[XAML]
<!-- Hard shadow on top of soft shadow. -->
<TextBlock
Text="Shadow Text"
Foreground="CornflowerBlue">
<TextBlock.BitmapEffect>
<BitmapEffectGroup>
<BitmapEffectGroup.Children>
<DropShadowBitmapEffect
ShadowDepth="5"
Direction="330"
Color="DarkSlateBlue"
Opacity="0.75"
Softness="0.50" />
<DropShadowBitmapEffect
ShadowDepth="2"
Direction="330"
Color="Maroon"
Opacity="0.5"
Softness="0.0" />
</BitmapEffectGroup.Children>
</BitmapEffectGroup>
</TextBlock.BitmapEffect>
</TextBlock>
|
26.2 How can I use a DoubleAnimation to rotate the textblock ?
|
|
The following example uses a DoubleAnimation to rotate the textblock. The
textblock performs a full rotation over a duration of 20 seconds and then
continues to repeat the rotation.
|
[XAML]
<TextBlock
Name="MyRotatingText"
Margin="20"
Width="640" Height="100" FontSize="48" FontWeight="Bold"
Foreground="Teal"
>
This is rotating text
<TextBlock.RenderTransform>
<RotateTransform x:Name="MyRotateTransform" Angle="0"
CenterX="230" CenterY="25"/>
</TextBlock.RenderTransform>
<!-- Animates the text block's rotation. -->
<TextBlock.Triggers>
<EventTrigger RoutedEvent="TextBlock.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="MyRotateTransform"
Storyboard.TargetProperty="(RotateTransform.Angle)"
From="0.0" To="360" Duration="0:0:10"
RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
|
26.3 What is the order in which the controls are rendered ?
|
|
The visual tree determines the rendering order of WPF visual and drawing
objects. The root of the visual tree is first rendered and then it's child
visual objects are traversed from left to right. If the visual object contains
a child object then it's child objects are traversed before the visual object's
siblings are traversed.
|
26.4 How do I enumerate child objects in a visual tree ?
|
|
We can define three paragraphs under one section as follows.
In the following example, the section has a "Background" property value of Red,
therefore the background color of the paragraphs is also red.
|
[XAML]
<FlowDocument
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- By default, Section applies no formatting to elements
contained
within it. However, in this example, the section has a
Background
property value of "Red", therefore, the three paragraphs (the
block)
inside the section also have a red background. -->
<Section Background="Red">
<Paragraph>
Paragraph 1
</Paragraph>
<Paragraph>
Paragraph 2
</Paragraph>
<Paragraph>
Paragraph 3
</Paragraph>
</Section>
</FlowDocument>
|
26.5 How rendering in WPF differs from WIN32 applications?
|
|
A WIN32 application uses immediate mode graphics system wherein the application
is responsible for repainting the client area when they are resized or the
object's visual appearance is changed. WPF on the contrary uses retained mode
graphics system. In this mode, drawing information of an object is persisted
and serialized by the application and the rendering is done by the system.
|
|