public override object?ConvertFromInvariantString(string?value)
        {
            if (value == null)
            {
                return(null);
            }

            value = value?.Trim();

            if (string.Compare(value, "top", StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(SKConfettiEmitterBounds.Top);
            }

            if (string.Compare(value, "left", StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(SKConfettiEmitterBounds.Left);
            }

            if (string.Compare(value, "right", StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(SKConfettiEmitterBounds.Right);
            }

            if (string.Compare(value, "bottom", StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(SKConfettiEmitterBounds.Bottom);
            }

            if (string.Compare(value, "center", StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(SKConfettiEmitterBounds.Center);
            }

            if (value?.IndexOf(',') == value?.LastIndexOf(','))
            {
                var pointConverter = new PointTypeConverter();
                var point          = (Point)pointConverter.ConvertFromInvariantString(value);
                return(SKConfettiEmitterBounds.Point(point));
            }

            var rectConverter = new RectTypeConverter();
            var rect          = (Rect)rectConverter.ConvertFromInvariantString(value);

            return(SKConfettiEmitterBounds.Bounds(rect));
        }
예제 #2
0
        public ConfettiPage()
        {
            InitializeComponent();

            Configs = new Dictionary <string, ConfettiConfig>
            {
                ["Top"]    = new ConfettiConfig(),
                ["Center"] = new ConfettiConfig
                {
                    MinSpeed       = 30,
                    MaxSpeed       = 150,
                    Duration       = 0,
                    OnCreateSystem = (i, system) =>
                    {
                        system.Emitter       = SKConfettiEmitter.Burst(100);
                        system.EmitterBounds = SKConfettiEmitterBounds.Center;
                    }
                },
                ["Sides"] = new ConfettiConfig(2)
                {
                    MinSpeed       = 50,
                    MaxSpeed       = 400,
                    Duration       = 0,
                    OnCreateSystem = (i, system) =>
                    {
                        system.Emitter = SKConfettiEmitter.Burst(100);
                        if (i % 2 == 0)
                        {
                            system.EmitterBounds = SKConfettiEmitterBounds.Point(0, Height);
                            system.StartAngle    = -85;
                            system.EndAngle      = -35;
                        }
                        else
                        {
                            system.EmitterBounds = SKConfettiEmitterBounds.Point(Width, Height);
                            system.StartAngle    = 265;
                            system.EndAngle      = 215;
                        }
                    }
                },
            };

            BindingContext = this;
        }