Introduction

This article demonstrates how to add custom background image animation for UWP in Xamarin.Forms application. This function is available in Universal Windows Platform applications.
Let's start.
Step 1

Create a Xamarin.Forms app by going to File >> New >> Visual C# >> Cross Platform >> Cross platform app (Xamarin.Native or Xamarin.Forms) and click OK.
( Project Name :CusBackImageAnimationApp)
Step 2

Now, select Blank App >>Platform (Android, IOS, Windows(UWP)) >> Xamarin.Forms >> .NET Standard and click OK.

Step 3

After the project creation, add User Control to your UWP application. For that, go to Solution Explorer >>select and right-click to CusBackImageAnimarionUserControl.UWP app followed by selecting Add >> New Item >> Visual C# >> User Control and give the page a name as BackgroundAnimationUserControl. Click OK.

Step 4

In this step, open BackgroungAnimationUserControl.Xaml page. For that, double-click to get its design view. Here is the code to be pasted into it.
Used toolbox items
  • Image - To use background animation
XAML Code
  1. <UserControl
  2. x:Class="BackgroundAnimation.BackgroundAnimationUserControl"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:BackgroundAnimation"
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8. mc:Ignorable="d">
  9. <Grid>
  10. <Grid.Triggers>
  11. <EventTrigger RoutedEvent="Grid.Loaded">
  12. <EventTrigger.Actions>
  13. <BeginStoryboard>
  14. <Storyboard>
  15. <DoubleAnimationUsingKeyFrames RepeatBehavior="Forever"
  16. Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)"
  17. Storyboard.TargetName="BackgroundImage"
  18. AutoReverse="True">
  19. <EasingDoubleKeyFrame KeyTime="0:0:20"
  20. Value="1.3">
  21. <EasingDoubleKeyFrame.EasingFunction>
  22. <SineEase EasingMode="EaseInOut" />
  23. </EasingDoubleKeyFrame.EasingFunction>
  24. </EasingDoubleKeyFrame>
  25. </DoubleAnimationUsingKeyFrames>
  26. <DoubleAnimationUsingKeyFrames RepeatBehavior="Forever"
  27. Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)"
  28. Storyboard.TargetName="BackgroundImage"
  29. AutoReverse="True">
  30. <EasingDoubleKeyFrame KeyTime="0:0:20"
  31. Value="1.3">
  32. <EasingDoubleKeyFrame.EasingFunction>
  33. <SineEase EasingMode="EaseInOut" />
  34. </EasingDoubleKeyFrame.EasingFunction>
  35. </EasingDoubleKeyFrame>
  36. </DoubleAnimationUsingKeyFrames>
  37. </Storyboard>
  38. </BeginStoryboard>
  39. </EventTrigger.Actions>
  40. </EventTrigger>
  41. </Grid.Triggers>
  42. <Image x:Name="BackgroundImage"
  43. Source="Images/logesh.JPG"
  44. Stretch="UniformToFill"
  45. RenderTransformOrigin="0.5,0.5">
  46. <Image.RenderTransform>
  47. <CompositeTransform/>
  48. </Image.RenderTransform>
  49. </Image>
  50. </Grid>
  51. </UserControl>
Step 5

Afterward, open Solution Explorer >> CusBackImageAnimationApp.UWP >> click open MainPage.xaml page. Given below is the code for this page.
XAML Code
  1. <Page
  2. x:Class="BackgroundAnimation.MainPage"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:BackgroundAnimation"
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8. mc:Ignorable="d">
  9. <local:BackgroundAnimationUserControl/>

  10. </Page>
Step 6

After the design view, go to Build menu and click "Configure Manager ". Here, you can configure your Universal Windows Platform startup settings.
Click F5 or "Build and Run " to run your UWP application. After running this project, you will get the result like below.

Finally, we have successfully changed a Xamarin.Forms custom UWP application in which we can change the background image.