When it comes to web pages, HTML is the tool to present the elements and CSS to provide the styling. Sure, there are exceptions and embellishments but, in short, that is how it boils down. If you want to implement some sort of animation or have something move, and it’s more complex than the simple animations supported by CSS, you generally have to fall back on JavaScript. In contrast, these aspects of presentation, styling, and animation are all an integral part of the Windows Presentation Foundation XAML.
XAML stands for Extensible Application Markup Language, and it is a declarative language that describes WPF’s elements, relationships, and behaviors. XAML elements map directly to Common Language Runtime (CLR) object instances and XAML attributes correspond to the properties and events of CLR objects.
In this tutorial, you will explore the various ways to animate visual elements in WPF. The case study application you’ll build will implement three buttons that respond to the mouse hovering over them with an animation.
All of the coding for this tutorial is accomplished using only XAML. If you ever have an application that will run on Windows, you may find it easier and faster to implement using WPF rather than a collection of tools used in a browser environment. Of course there are trade offs, but WPF may be the right tool for the job.
Animations are nothing more than manipulations of properties over time. To define an animation, you have to tell it the following:
You’ll need the following tools and resources to build and run this project:
Windows 10 – It puts Windows in the Windows Presentation Foundation.
.NET Core SDK 3.1 – The SDK includes the APIs, runtime, and CLI.
Visual Studio 2019 with the following workloads and individual components:
You should have a general knowledge of Visual Studio and the C## language syntax. You will be adding and editing files and debugging code.
There is a companion repositoryfor this post available on GitHub. It contains the complete source code for the tutorial project.
Begin this tutorial by creating a WPF App (.NET Core) project for C## named WpfAnimationIntro. You can put the solution and project folders wherever it’s most convenient for you.
#code # tutorials and hacks #code # tutorials and hacks