private void OnTouchAction(object sender, TouchActionEventArgs args) { if (args.Type == TouchActionType.Entered) { IsMouseOver = true; } else if (args.Type == TouchActionType.Exited) { IsPressed = false; IsMouseOver = false; } else if (args.Type == TouchActionType.Pressed) { IsPressed = true; } else if (args.Type == TouchActionType.Released && IsPressed) { IsPressed = false; IsToggled = !IsToggled; IsToggledChanged?.Invoke(this, IsToggled); ToggledCommand?.Execute(null); } }
/// <summary> /// Handle IsToggled changes /// </summary> protected void OnIsToggledChangedInternal(bool newValue) { if (string.IsNullOrEmpty(ToggledText) == false && string.IsNullOrEmpty(ToggledText) == false) { if (IsToggled) { Text = ToggledText; } else { Text = UnToggledText; } } if (IsToggled) { VisualStateManager.GoToState(this, ToggledStateName); } else { VisualStateManager.GoToState(this, DefaultStateName); } _toggledAnimationProcess = newValue ? 1 : 0; _skiaCanvas.InvalidateSurface(); OnIsToggledChanged(IsToggled); if (IsToggledChanged != null) { IsToggledChanged(this, IsToggled); } if (UnToggledCommand != null && IsToggled == false) { UnToggledCommand.Execute(CommandParameter); } if (ToggledCommand != null && IsToggled == true) { ToggledCommand.Execute(CommandParameter); } }