Ugrás a tartalomhoz

.NET Programming Technologies

Gergely Kovásznai, Csaba Biró

Eszterházy Károly College

9. fejezet - Effects (written by Csaba Biró)

9. fejezet - Effects (written by Csaba Biró)

One of the great power of WPF is that almost all GUI elements can easily be associated with different effect. Various effects can be created with using effects (shading, outer glow, embossing, etc.). Every effect is the descendant of System.Windows.Media.Effects.Effect class.

Effects

First, let’s look through several tasks how can we create different shades for individual controls.

DropShadowEffect

The easiest way is the adaptation of DropShadowEffect, which place a shadow behind the element.

DropShadowEffect properties

BlurRadius        shadow blur radius,

Color        shadow color,

Direction        shadow direction,

Opacity        shadow opacity,

RenderingBias        shadow rendering bias,

ShadowDepth        shadow depth.

Example IX.1 Effekt hozzárendelése egy Border-hez

<Border>

        <Border.Effect >

                <DropShadowEffect

                ShadowDepth=""

                Opacity=""

                Color=""

                Direction=""/>

         </Border.Effect>

</Border>

Examlpe IX.2 Shadow1

IX.1. Shadow 1

<TextBlock Text="Shadow1" Foreground="Teal" FontSize="22">

            <TextBlock.Effect>

                <DropShadowEffect

                              ShadowDepth="4"

                              Direction="330"

                              Color="Red"

                              Opacity="0.5"

                              BlurRadius="4"/>

            </TextBlock.Effect>

</TextBlock>

Example IX.3 Shadow2

IX.2. Shadow 2

<TextBlock Foreground="Black" Text="Shadow2"

  Grid.Column="0" Grid.Row="0">

        <TextBlock.RenderTransform>

                <TranslateTransform X="3" Y="3" />

         </TextBlock.RenderTransform>

</TextBlock>

<TextBlock Foreground="Coral" Text="Shadow2" Grid.Column="0" Grid.Row="0">

</TextBlock>

BlurEffect

The GUI elements seem to be blurred with the help of it.

BlurEffect properties:

Radius        blur radius,

KernelType        kernel type

RenderingBias        rendering bias.

Example IX.4 BlurEffect

IX.3. BlurEffect

<TextBlock Text="What’s this?" Foreground="Green" FontSize="40"

           Grid.Column="0" Grid.Row="0" >

          <TextBlock.Effect>

                 <BlurEffect

                    Radius="16"

                    KernelType="Gaussian"/>

          </TextBlock.Effect>

</TextBlock>