Skip to Content
Learning C# 3.0
book

Learning C# 3.0

by Jesse Liberty, Brian MacDonald
November 2008
Beginner
696 pages
17h 43m
English
O'Reilly Media, Inc.
Content preview from Learning C# 3.0

Animations

This control and resource stuff is great, but it’s not exactly exciting, we know. We promised you animations, and animations you shall have. The best way to make animations in WPF is with a tool called Expression Blend (available at http://www.microsoft.com/expression), but in this case, we’ll show you how to do it the hard way so that you’ll know what’s going on in the XAML. In this example, you’re going to start with a simple square, and perform some of the more basic animations on it. The square is in fact an instance of the built-in Rectangle control, which is part of the WPF schema. However, you can apply these animations to many other controls.

The first thing to do is define the Rectangle control. Create a new WPF project to start with. You could drag a Rectangle control out of the toolbar onto the window, but in this case, it’s easier to just define the rectangle in the XAML. Add the following element inside the <Grid> element:

<Rectangle Name="myRectangle" Width="100" Height="100">
</Rectangle>

Now you should see a square in the Design window, 100 units on a side. You didn’t define the Margin property, so the square will be centered in the window, which is fine. The first thing you’re going to do is animate the color of the square, and to do that, you’ll need the square to have some color first. If you click on the Rectangle element, you’ll see it has a Fill property, which is the interior color of the square (as opposed to the outside border, which we’ll leave ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

C# 3.0 Design Patterns

C# 3.0 Design Patterns

Judith Bishop
Programming in C#: Exam 70-483 (MCSD) Guide

Programming in C#: Exam 70-483 (MCSD) Guide

Simaranjit Singh Bhalla, SrinivasMadhav Gorthi
C# 7.0 in a Nutshell

C# 7.0 in a Nutshell

Joseph Albahari, Ben Albahari

Publisher Resources

ISBN: 9780596155018Errata Page