未加星标

Offset Animation Application Using UWP With XAML And C#

字体大小 | |
[系统(windows) 所属分类 系统(windows) | 发布者 店小二05 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

Before reading this article, please go through the article's link given below.

Introduction To Universal windows Platform (UWP) App Development Using Windows 10 And Visual Studio 2015

Offset animation behavior gets the number of pixels from the origin of the associated control and subsequently offsets the control.

After reading this article, you can learn how to develop Offset Animation Application in Universal Windows apps development with XAML and Visual C#.

The important tools required to developing UWP are-

Windows 10 (Recommended) Visual Studio 2015 Community Edition (It is a free software available online)

Now, we can discuss step by step app development.

Step 1

Open Visual Studio 2015 -> Start -> New Project-> Select Universal (under Visual C#->Windows)-> Blank app -> Give the suitable name for your app (UWPOffsetAnimation)->OK.

After choosing the target and minimum platform version for your Windows, Universal Application will support and the project creates App.xaml and MainPage.xaml.

Step 2

Open (double click) the file MainPage.xaml in the Solution Explorer and add Microsoft.Toolkit.Uwp.UI.Animations reference in the project.

To add the reference, right click Your Project (UWPOffsetAnimation) and select Manage Nuget Packages.

Choose Browse and search Microsoft.Toolkit.Uwp.UI.Animations, select the package and install it.


Offset Animation Application Using UWP With XAML And C#

Accept the Licence.


Offset Animation Application Using UWP With XAML And C#

The reference is added to your project.


Offset Animation Application Using UWP With XAML And C#

Step 3

Add TextBlock control, change the name and text property for the title.
Offset Animation Application Using UWP With XAML And C#

Step 4

Add images in the Assets folder, images for Offset.
Offset Animation Application Using UWP With XAML And C#

Step 5

Add the image control to display the image for an offset.
Offset Animation Application Using UWP With XAML And C#

Add another two image controls to display the image for an offset.


Offset Animation Application Using UWP With XAML And C#

Step 6

Add XAML namespaces, given below and code for Offset in Mainpage.xaml. xmlns:interactivity="using:Microsoft.Xaml.Interactivity" xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors" xmlns:core="using:Microsoft.Xaml.Interactions.Core"<Imagex:Name="imgInsect1" HorizontalAlignment="Left" Height="41" Margin="279,309,0,0" VerticalAlignment="Top" Width="27" Source="Assets/insect.jpg"><interactivity:Interaction.Behaviors><behaviors:Offsetx:Name="offset"/></interactivity:Interaction.Behaviors></Image>

Add offset code to all the images.


Offset Animation Application Using UWP With XAML And C#

Add a button control and add a click Event method for Offset action.


Offset Animation Application Using UWP With XAML And C#

Note

Automatically, the code, given below will be generated in XAML code view, while we are done in the design view.

<Pagex:Class="UWPOffsetAnimation.MainPage"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="using:UWPOffsetAnimation"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:interactivity="using:Microsoft.Xaml.Interactivity"xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors"xmlns:core="using:Microsoft.Xaml.Interactions.Core"mc:Ignorable="d"> <GridBackground="{ThemeResourceApplicationPageBackgroundThemeBrush}"> <TextBlockx:Name="tblTitle"HorizontalAlignment="Left"Margin="188,59,0,0"TextWrapping="Wrap"Text="UWPOffsetAnimationDemo"VerticalAlignment="Top"FontWeight="Bold"FontSize="20"/> <Imagex:Name="imgInsect1"HorizontalAlignment="Left"Height="41"Margin="279,309,0,0"VerticalAlignment="Top"Width="27"Source="Assets/insect.jpg"> <interactivity:Interaction.Behaviors> <behaviors:Offsetx:Name="offset"/></interactivity:Interaction.Behaviors> </Image> <Imagex:Name="imgInsect2"HorizontalAlignment="Left"Height="41"Margin="327,309,0,0"VerticalAlignment="Top"Width="27"Source="Assets/insect.jpg"> <interactivity:Interaction.Behaviors> <behaviors:Offsetx:Name="offset1"/></interactivity:Interaction.Behaviors> </Image> <Imagex:Name="imgInsect3"HorizontalAlignment="Left"Height="41"Margin="235,309,0,0"VerticalAlignment="Top"Width="27"Source="Assets/insect.jpg"> <interactivity:Interaction.Behaviors> <behaviors:Offsetx:Name="offset2"/></interactivity:Interaction.Behaviors> </Image> <Buttonx:Name="btnCome"Content="Come"HorizontalAlignment="Left"Margin="540,86,0,0"VerticalAlignment="Top"Click="btnCome_Click"/></Grid> </Page>

Step 7

Add namespace and the code, given below in MainPage.xaml.cs. usingMicrosoft.Toolkit.Uwp.UI.Animations; privateasyncvoidbtnCome_Click(objectsender,RoutedEventArgse) { intx=10,y=10; for(inti=0;i<5;i++){ awaitimgInsect1.Offset(duration:0,delay:100,offsetX:x,offsetY:y).StartAsync(); awaitimgInsect2.Offset(duration:0,delay:100,offsetX:x,offsetY:y).StartAsync(); awaitimgInsect3.Offset(duration:0,delay:100,offsetX:x,offsetY:y).StartAsync(); y=y-50; } }
Offset Animation Application Using UWP With XAML And C#

Step 8


Deploy your app in the local machine and the output of the UWPOffsetAnimation app is given below.
Offset Animation Application Using UWP With XAML And C#

Afterwards, Come button is clicked.


Offset Animation Application Using UWP With XAML And C#

Summary

Now, you have successfully tested UWP ToolKit Offset Animation in Visual C# - UWP environment.

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

主题: C#WindowsVisual StudiVisual StudioUW
分页:12
转载请注明
本文标题:Offset Animation Application Using UWP With XAML And C#
本站链接:http://www.codesec.net/view/480939.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(37)