Welcome to MSDN Blogs Sign in | Join | Help

You had me at "Hello World!"

XAML, WPF, Silverlight, .NET, Office 2007, Windows code samples and other interesting things

Syndication

Blobbying #1 - Introducing Blob the Builder

Do you remember long time ago when you (or someone else) used to play with small and cute snails, dirt, and sticky, slimy things?

The blobs are here again!

Remember your most precious childhood memories (where applicable) with this short blobbyfying experience.

 

Above is what we are going to do. I tried to pick up nice names for each of the blobs.

I like the Ema blob most thus Ema can be clicked and respond to the click.

 

Now the surprise (???): Each of the blobs is made of just one <Border> tag!!

Can it get easier than this? You weren't surprised, were you?

 

Here's the code for Ricky:

 

    <Border BorderThickness="10" BorderBrush="Blue" Background="BlanchedAlmond"  CornerRadius="100,40,5,15" HorizontalAlignment="Left" Margin="20,33,0,0" Width="103" Height="110" VerticalAlignment="Top">

      <Grid>

        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">Ricky</TextBlock>

      </Grid>

    </Border>

 

As you can see it's just a border with the CornerRadius set to some values.

If you can't wait to experiment jump to the sample code .

Or you can have more patience and do not rush to brutally modify the blobs.

 

Let's start with Ema:

 

    <Border Name="Ema" BorderThickness="10,10,10,10" CornerRadius="50,80,30,45" HorizontalAlignment="Left" Margin="84,186,0,0" Width="103" Height="110" VerticalAlignment="Top">

      <Border.Background>

        <RadialGradientBrush GradientOrigin="0.2, 0.2">

          <RadialGradientBrush.GradientStops>

            <GradientStop Color="#FFFFFFFF" Offset="0.1" />

            <GradientStop Color="#0F0000FF" Offset="1.4" />

          </RadialGradientBrush.GradientStops>

        </RadialGradientBrush>

      </Border.Background>

      <Grid>

          <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Ema"/>

      </Grid>

    </Border>

 

Looks like:

How did she become so pretty?

1.       Using brushes opacity less than 1 usually looks cool.

2.       Radial gradient brushes with GradientOrigin other than center look nice

 

Agreed?

 

Now a simple tweak to make her even more beautiful!

Just copy the Background to the BorderBrush:

 

    <Border Name="Ema" BorderThickness="10,10,10,10" CornerRadius="50,80,30,45" HorizontalAlignment="Left" Margin="84,186,0,0" Width="103" Height="110" VerticalAlignment="Top">

      <Border.BorderBrush>

        <RadialGradientBrush GradientOrigin="0.2, 0.2">

          <RadialGradientBrush.GradientStops>

            <GradientStop Color="#FFFFFFFF" Offset="0.1" />

            <GradientStop Color="#0F0000FF" Offset="1.4" />

          </RadialGradientBrush.GradientStops>

        </RadialGradientBrush>

      </Border.BorderBrush>

      <Border.Background>

        <RadialGradientBrush GradientOrigin="0.2, 0.2">

          <RadialGradientBrush.GradientStops>

            <GradientStop Color="#FFFFFFFF" Offset="0.1" />

            <GradientStop Color="#0F0000FF" Offset="1.4" />

          </RadialGradientBrush.GradientStops>

        </RadialGradientBrush>

      </Border.Background>

      <Grid>

          <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Ema"/>

      </Grid>

    </Border>

 

And...

Nicely plopped on the form!

 

Instead of having to copy the brush you could as well try:

 

BorderBrush="{Binding RelativeSource={RelativeSource Self}, Path=(Control.Background)}"

 

And see if it works.

 

Animating Our Blob

 

Imagine pressing a keyboard key. As my fellow Cider Comrade Richard mentioned: "the light goes to the right and bottom".

 

This means that we'll animate the white dot in the radial brush (which is the GradientOrigin to go "down and right". We'll move it from 0.2, 0.2 to 0.24, 0.24.

We'll also make the white appear a little smaller by animating the (RadialGradientBrush.GradientStops)[0].(Offset) - that's one of the gradient stops from 0.1 to 0.0.

All of this happens on mouse down ({StaticResource Enblob}), on mouse up we'll do the reverse ({StaticResource Deblob}).

We'll also need to move the "Ema" text to the bottom and right. To make it easier we'll place the text in a ViewBox and move the ViewBox instead. This way we can place anything in the ViewBox and it will be moved automatically.

 

<Border ...>

...

      <Grid>

        <Viewbox Stretch="None" Name="Boxy" Margin="0,0,0,0">

          <Grid>

            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Ema"/>

          </Grid>

        </Viewbox>

      </Grid>

    </Border>

 

The ViewBox is moved by animating its Margin property from 0,0,0,0 to 4,4,0,0.

 

The actual animation code:

Moving the GradientOrigin down and right:

 

        <PointAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Ema"

        Storyboard.TargetProperty="(Control.Background).(RadialGradientBrush.GradientOrigin)" >

          <PointAnimationUsingKeyFrames.KeyFrames>

            <PointKeyFrameCollection>

              <SplinePointKeyFrame  KeySpline="0.5,0.5,0.5,0.5" Value="0.2, 0.2" KeyTime="00:00:00.0000000" />

              <SplinePointKeyFrame  KeySpline="0.5,0.5,0.5,0.5" Value="0.24, 0.24" KeyTime="00:00:00.1000000" />

            </PointKeyFrameCollection>

          </PointAnimationUsingKeyFrames.KeyFrames>

        </PointAnimationUsingKeyFrames>

 

 

Animating the gradient stop to make the white smaller:

 

        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Ema"

    Storyboard.TargetProperty="(Control.Background).(RadialGradientBrush.GradientStops)[0].(Offset)" >

          <DoubleAnimationUsingKeyFrames.KeyFrames>

            <DoubleKeyFrameCollection>

              <SplineDoubleKeyFrame KeySpline="0.5,0.5,0.5,0.5" Value="0.1" KeyTime="00:00:00.0000000" />

              <SplineDoubleKeyFrame KeySpline="0.5,0.5,0.5,0.5" Value="0.0" KeyTime="00:00:00.1000000" />

            </DoubleKeyFrameCollection>

          </DoubleAnimationUsingKeyFrames.KeyFrames>

        </DoubleAnimationUsingKeyFrames>

      </Storyboard>

 

 

Moving the container ViewBox by 4, 4 to the down and right:

 

        <ThicknessAnimation Storyboard.TargetName="Boxy"

          Storyboard.TargetProperty="(Control.Margin)"

          Duration="0:0:0.1" FillBehavior="HoldEnd" From="0,0,0,0" To="4,4,0,0" />

 

That's how we got the Ema clickability.

The example XAML can be opened in the Cider designer (JuneCTP should do).

 

Disclaimer: No blobs have been harmed in any way while writing this blog entry. The views expressed here are solely mine and not Microsoft's. The code snippets, blobs and everything is provided "as is". There are no warranties for fitness of the blobs and/or code snippets for particular use. The names used here are not names of actual blobs and/or people. Any resemblance to real life events is a pure coincidence.

Published Wednesday, August 02, 2006 12:12 PM by nikola

Filed under: ,

Attachment(s): Blobs.xaml

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, July 21, 2007 10:32 PM

Sorry :(

Constandinos

# re: Blobbying #1 - Introducing Blob the Builder @ Tuesday, July 24, 2007 10:15 PM

Nice!

Aniketos

# re: Blobbying #1 - Introducing Blob the Builder @ Wednesday, July 25, 2007 3:28 AM

Nice...

Fotis

# re: Blobbying #1 - Introducing Blob the Builder @ Wednesday, July 25, 2007 9:56 PM

Nice

Milos

# re: Blobbying #1 - Introducing Blob the Builder @ Thursday, July 26, 2007 1:54 PM

interesting

Apostolos

# re: Blobbying #1 - Introducing Blob the Builder @ Friday, July 27, 2007 6:53 AM

Interesting...

Nickolas

# re: Blobbying #1 - Introducing Blob the Builder @ Friday, July 27, 2007 6:54 AM

Cool...

Socrates

# re: Blobbying #1 - Introducing Blob the Builder @ Friday, July 27, 2007 6:26 PM

Cool!

Ioannis

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, July 28, 2007 3:48 AM

Nice...

Fotis

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, July 28, 2007 7:00 AM

Nice!

Adonis

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, July 28, 2007 3:25 PM

Cool.

Haralambos

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, July 28, 2007 10:10 PM

Sorry :(

Cletus

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, July 28, 2007 10:37 PM

Nice...

Spyridon

# re: Blobbying #1 - Introducing Blob the Builder @ Sunday, July 29, 2007 1:25 AM

Cool!

Loukianos

# re: Blobbying #1 - Introducing Blob the Builder @ Sunday, July 29, 2007 11:30 AM

Nice

Anastassios

# re: Blobbying #1 - Introducing Blob the Builder @ Sunday, July 29, 2007 8:35 PM

Nice!

Glafkos

# re: Blobbying #1 - Introducing Blob the Builder @ Monday, July 30, 2007 1:57 AM

Nice

Athones

# re: Blobbying #1 - Introducing Blob the Builder @ Monday, July 30, 2007 2:04 AM

Interesting...

Sterghios

# re: Blobbying #1 - Introducing Blob the Builder @ Monday, July 30, 2007 6:27 AM

Nice...

Agapios

# re: Blobbying #1 - Introducing Blob the Builder @ Monday, July 30, 2007 11:00 AM

Nice!

Yioryios

# re: Blobbying #1 - Introducing Blob the Builder @ Monday, July 30, 2007 11:39 AM

interesting

Georges

# re: Blobbying #1 - Introducing Blob the Builder @ Monday, July 30, 2007 3:22 PM

Nice...

Dimitri

# re: Blobbying #1 - Introducing Blob the Builder @ Monday, July 30, 2007 8:05 PM

Cool...

Sophocles

# re: Blobbying #1 - Introducing Blob the Builder @ Tuesday, July 31, 2007 3:25 AM

Interesting...

Tataki

# re: Blobbying #1 - Introducing Blob the Builder @ Wednesday, August 01, 2007 12:03 AM

Cool!

Martinos

# re: Blobbying #1 - Introducing Blob the Builder @ Wednesday, August 01, 2007 11:30 AM

Interesting...

Orion

# re: Blobbying #1 - Introducing Blob the Builder @ Thursday, August 02, 2007 3:22 AM

Interesting...

Drymiotes

# re: Blobbying #1 - Introducing Blob the Builder @ Thursday, August 02, 2007 3:29 PM

Cool.

Dionyssios

# re: Blobbying #1 - Introducing Blob the Builder @ Thursday, August 02, 2007 6:32 PM

Nice

Anastassios

# re: Blobbying #1 - Introducing Blob the Builder @ Friday, August 03, 2007 5:46 AM

Cool...

Dionyssios

# re: Blobbying #1 - Introducing Blob the Builder @ Friday, August 03, 2007 10:20 AM

Nice!

Agias

# re: Blobbying #1 - Introducing Blob the Builder @ Friday, August 03, 2007 5:51 PM

Nice

Alexios

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, August 04, 2007 3:18 AM

Cool.

Theologos

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, August 04, 2007 9:02 AM

Cool.

Aniketos

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, August 04, 2007 9:50 AM

Cool...

Athanassios

# re: Blobbying #1 - Introducing Blob the Builder @ Sunday, August 05, 2007 9:05 PM

interesting

Manolis

# re: Blobbying #1 - Introducing Blob the Builder @ Sunday, August 05, 2007 11:46 PM

Nice!

Charalampos

# re: Blobbying #1 - Introducing Blob the Builder @ Monday, August 06, 2007 12:40 AM

Cool.

Argyros

# re: Blobbying #1 - Introducing Blob the Builder @ Monday, August 06, 2007 10:53 AM

Nice!

Vangelis

# re: Blobbying #1 - Introducing Blob the Builder @ Monday, August 06, 2007 11:59 AM

Interesting...

Gregorios

# re: Blobbying #1 - Introducing Blob the Builder @ Monday, August 06, 2007 3:08 PM

Nice...

Stylianos

# re: Blobbying #1 - Introducing Blob the Builder @ Monday, August 06, 2007 9:19 PM

Nice!

Dimitri

# re: Blobbying #1 - Introducing Blob the Builder @ Tuesday, August 07, 2007 4:54 AM

interesting

Pavlos

# re: Blobbying #1 - Introducing Blob the Builder @ Tuesday, August 07, 2007 12:10 PM

interesting

Haralambos

# re: Blobbying #1 - Introducing Blob the Builder @ Tuesday, August 07, 2007 1:35 PM

Nice

Apostolis

# re: Blobbying #1 - Introducing Blob the Builder @ Tuesday, August 07, 2007 6:57 PM

Interesting...

Aineias

# re: Blobbying #1 - Introducing Blob the Builder @ Wednesday, August 08, 2007 1:33 AM

Nice...

Epameinondas

# re: Blobbying #1 - Introducing Blob the Builder @ Wednesday, August 08, 2007 5:34 PM

Nice!

Ivan

# re: Blobbying #1 - Introducing Blob the Builder @ Wednesday, August 08, 2007 8:43 PM

Sorry :(

Iakovos

# re: Blobbying #1 - Introducing Blob the Builder @ Wednesday, August 08, 2007 8:49 PM

Sorry :(

Leonidas

# re: Blobbying #1 - Introducing Blob the Builder @ Wednesday, August 08, 2007 9:27 PM

interesting

Theodore

# re: Blobbying #1 - Introducing Blob the Builder @ Thursday, August 09, 2007 3:05 AM

Interesting...

Alexis

# re: Blobbying #1 - Introducing Blob the Builder @ Thursday, August 09, 2007 3:20 AM

Cool!

Vaggelis

# re: Blobbying #1 - Introducing Blob the Builder @ Friday, August 10, 2007 7:51 AM

Nice...

Lazaros

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, August 11, 2007 8:52 AM

Cool...

Tzannas

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, August 11, 2007 9:43 AM

Nice...

Sophocles

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, August 11, 2007 3:29 PM

Nice

Drymiotes

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, August 11, 2007 3:53 PM

Nice

George

# re: Blobbying #1 - Introducing Blob the Builder @ Saturday, August 11, 2007 4:19 PM

interesting

Sotirios

# re: Blobbying #1 - Introducing Blob the Builder @ Sunday, August 12, 2007 8:35 AM

interesting

Kyriakos

# re: Blobbying #1 - Introducing Blob the Builder @ Sunday, August 12, 2007 3:33 PM

Nice

Ivan

# re: Blobbying #1 - Introducing Blob the Builder @ Sunday, August 12, 2007 4:36 PM

Nice...

Alexios

# re: Blobbying #1 - Introducing Blob the Builder @ Sunday, August 12, 2007 11:39 PM

Cool.

Ari

# re: Blobbying #1 - Introducing Blob the Builder @ Monday, August 13, 2007 3:15 AM

Sorry :(

Giannis

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
Page view tracker