Particles.Forms

September 7, 2020 ยท View on GitHub

A Xamarin.Forms library to display particles e.g. confetti. Should work on all platforms.

Get it from NuGet Nuget

Preview

API Reference

The starting point is the class ParticleView.

BindablePropertyDefaultDescription
IsActivetrueWhether or not the control is displaying particles. Use this property to stop and restart the particles.
IsRunningtrueWhether or not the control is animating particles. Use this property to pause and resume the particles.
HasFallingParticlesfalseWhether or not falling particles should be shown.
FallingParticlesPerSecond60Amount of new particles to be added every second when HasFallingParticles is true.
AddParticlesOnTapfalseWhether or not to add particles on tap.
TapParticleCount30Amount of particles to add on tap when AddParticlesOnTap is true.
AddParticlesOnDragfalseWhether or not to add particles on drag.
DragParticleCount60Amount of particles to add on drag when AddParticlesOnDrag is true.
DragParticleMoveTypeParticleMovetype.FallParticle movement type while dragging.
UseSKGLViewFalse on all platforms except AndroidWhether or not to use the hardware-accelerated view for drawing.
ShowDebugInfoFalseWhether or not to show debug information.
DebugInfoColorLawnGreenColor to use when displaying debug information.

These properties aren't bindable.

PropertyDefaultDescription
TouchParticleGeneratorSimpleParticleGeneratorA ParticleBase generator to be used when interacting with the ParticleView
FallingParticleGeneratorFallingParticleGeneratorA ParticleBase generator to be used when showing particles that fall from the top edge to the bottom
CanvasSizeContains the current canvas size

Usage Sample

<?xml version="1.0" encoding="utf-8"?>

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:forms="clr-namespace:Particle.Forms;assembly=Particle.Forms"
             x:Class="Particle.Forms.Sample.Demo2.Demo2"
             Title="Custom Particles">
    <ContentPage.Resources>
        <x:Array Type="{x:Type Color}" x:Key="ConfettiColors">
            <Color>#a864fd</Color>
            <Color>#29cdff</Color>
            <Color>#78ff44</Color>
            <Color>#ff718d</Color>
            <Color>#fdff6a</Color>
            <Color>#ffcbf2</Color>
        </x:Array>
    </ContentPage.Resources>

    <Grid VerticalOptions="FillAndExpand"
          BackgroundColor="White"
          Margin="0 ,0, 0, 5">


        <forms:ParticleView x:Name="MyParticleCanvas"
                            IsActive="True"
                            IsRunning="True"
                            HasFallingParticles="True"
                            FallingParticlesPerSecond="20"
                            Margin="0, 20"
                            VerticalOptions="FillAndExpand"
                            HorizontalOptions="FillAndExpand"
                            ParticleColors="{StaticResource ConfettiColors}" />
    </Grid>
</ContentPage>

Tip

To conserver resources you can pause the particles when the Page is about to disappear and resume when the Page is about to appear.

        protected override void OnAppearing()
        {
            base.OnAppearing();

            MyParticleCanvas.IsRunning = true;
        }

        protected override void OnDisappearing()
        {
            base.OnDisappearing();

            MyParticleCanvas.IsRunning = false;
        }