protected override void OnDisconnected(UIElement oldElement)
 {
     // Dispose Light and Composition resources when it is removed from the tree
     HoverLight.RemoveTargetElement(GetId(), oldElement);
     CompositionLight.Dispose();
     _lightPositionExpression.Dispose();
     _offsetAnimation.Dispose();
 }
        protected override void OnConnected(UIElement targetElement)
        {
            if (targetElement == null)
            {
                return;
            }

            Compositor compositor = Window.Current.Compositor;

            // Create SpotLight and set its properties

            SpotLight spotLight = compositor.CreateSpotLight();

            spotLight.InnerConeColor = Colors.FloralWhite;
            spotLight.OuterConeColor = Colors.FloralWhite;

            spotLight.InnerConeAngleInDegrees = 0f;
            spotLight.InnerConeIntensity      = 4;
            //spotLight.OuterConeAngleInDegrees = 3f;

            spotLight.ConstantAttenuation  = 1f;
            spotLight.LinearAttenuation    = 0.253f;
            spotLight.QuadraticAttenuation = 0.58f;
            spotLight.Offset = new Vector3(0, 0, 0);

            // Associate CompositionLight with XamlLight
            this.CompositionLight = spotLight;

            // Define resting position Animation
            Vector3 restingPosition            = new Vector3(200, 200, 400);
            CubicBezierEasingFunction cbEasing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.3f, 0.7f), new Vector2(0.9f, 0.5f));

            _offsetAnimation = compositor.CreateVector3KeyFrameAnimation();
            _offsetAnimation.InsertKeyFrame(1, restingPosition, cbEasing);
            _offsetAnimation.Duration = TimeSpan.FromSeconds(0.5f);

            //spotLight.Offset = restingPosition;

            // Define expression animation that relates light's offset to pointer position
            CompositionPropertySet hoverPosition = ElementCompositionPreview.GetPointerPositionPropertySet(targetElement);

            _lightPositionExpression = compositor.CreateExpressionAnimation("Vector3(hover.Position.X, hover.Position.Y, height)");
            _lightPositionExpression.SetReferenceParameter("hover", hoverPosition);
            _lightPositionExpression.SetScalarParameter("height", 150f);

            // Configure pointer entered/ exited events
            targetElement.PointerMoved  += TargetElement_PointerMoved;
            targetElement.PointerExited += TargetElement_PointerExited;

            // Add UIElement to the Light's Targets
            HoverLight.AddTargetElement(GetId(), targetElement);
            //MoveToRestingPosition();
        }