Exemplo n.º 1
0
        /// <summary>
        /// Reflect the checked event change on the UI
        /// with a small animation
        /// </summary>
        /// <param name="isChecked"></param>
        ///
        void ApplyCheckedState()
        {
            Animation storyboard      = new Animation();
            Animation fadeAnim        = null;
            Animation checkBounceAnim = null;
            Animation checkFadeAnim   = null;
            double    fadeStartVal    = 0;
            double    fadeEndVal      = 1;
            double    scaleStartVal   = 0;
            double    scaleEndVal     = 1;
            Easing    checkEasing     = Easing.CubicIn;

            if (IsChecked)
            {
                checkedImage.Scale = 0;
                fadeStartVal       = 0;
                fadeEndVal         = 1;
                scaleStartVal      = 0;
                scaleEndVal        = 1;
                checkEasing        = Easing.CubicIn;
            }
            else
            {
                fadeStartVal  = 1;
                fadeEndVal    = 0;
                scaleStartVal = 1;
                scaleEndVal   = 0;
                checkEasing   = Easing.CubicOut;
            }
            fadeAnim = new Animation(
                callback: d => checkedBackground.Opacity = d,
                start: fadeStartVal,
                end: fadeEndVal,
                easing: Easing.CubicOut
                );
            checkFadeAnim = new Animation(
                callback: d => checkedImage.Opacity = d,
                start: fadeStartVal,
                end: fadeEndVal,
                easing: checkEasing
                );
            checkBounceAnim = new Animation(
                callback: d => checkedImage.Scale = d,
                start: scaleStartVal,
                end: scaleEndVal,
                easing: checkEasing
                );

            storyboard.Add(0, 0.6, fadeAnim);
            storyboard.Add(0, 0.6, checkFadeAnim);
            storyboard.Add(0.4, 1, checkBounceAnim);
            storyboard.Commit(this, "checkAnimation", length: 600);

            if (CheckedChangedCommand != null && CheckedChangedCommand.CanExecute(this))
            {
                CheckedChangedCommand.Execute(this);
            }
        }
Exemplo n.º 2
0
 void tapped()
 {
     if (!IsChecked)
     {
         IsChecked = true;
     }
     setCheckedState(IsChecked);
     if (CheckedChangedCommand != null && CheckedChangedCommand.CanExecute(this))
     {
         CheckedChangedCommand.Execute(this);
     }
 }