Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The concrete operation method of realizing WPF animation by C++

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you the specific operation methods of C++ to achieve WPF animation, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.

C++ programming language should be in a wide range of ways, which can help us to easily achieve many functional requirements.

Many people are used to using Blend to help edit XAML files and generate a lot of animation. But in the actual development, using the code to achieve animation is still very practical, and the logic of the code development ability is stronger, easier to control, this aspect of C# examples have been many, the following I introduce a few C++ WPF animation examples.

First of all, I will introduce the gradual emergence of less and less, that is, Alpha Animation. The animation code for C++ to implement WPF is as follows

/ *

* Take Label for example

, /

/ / 1, Find the lable by its name, The name define in the xaml file

Label^ pColorLabel = (label^) page- > FindName ("ColorAnimationLabel")

/ / 2, Define a DoubleAnimation object

Double pDoubleAnimation ^ gcnew DoubleAnimation ()

/ / 3, Set from to and duration

PDoubleAnimation- > From = 1

PDoubleAnimation- > To = 0

PDoubleAnimation- > DurationDuration = Duration (TimeSpan::FromSeconds (3))

/ / 4, Create a storyboard (Timeline)

Storyboard ^ pStoryboard = gcnew Storyboard ()

/ / 5, Set the DoubleAnimation's target name

PStoryboard- > SetTargetName (pDoubleAnimation, _ T ("ColorAnimationLabel"))

/ / 6, Set the DoubleAnimation's property

PStoryboard- > SetTargetProperty (pDoubleAnimation

Gcnew PropertyPath (Label::OpacityProperty))

/ / 7, Add the DoubleAnimation object to the storyboard

PStoryboard- > Children- > Add (pDoubleAnimation)

/ / 8, Start the animation

PStoryboard- > Begin (pColorLabel)

The XAML used by C++ above to implement the WPF animation code is as follows

< Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

< Grid>

< DockPanel>

< Button Name="ColorAnmationButton" Width="100" Height="50" Background="LightBlue">

Color Anmation

< /Button>

< Label Name="ColorAnimationLabel" Width="200" Height="50" Background="Red">

< /Label>

< /DockPanel>

< /Grid>

< /Page>

The above is the specific operation of C++ to achieve WPF animation, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report