private void OnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs) { var innerContent = (Content as FrameworkElement); double width, height; if (RippleAssist.GetIsCentered(this) && innerContent != null) { width = innerContent.ActualWidth; height = innerContent.ActualHeight; } else { width = sizeChangedEventArgs.NewSize.Width; height = sizeChangedEventArgs.NewSize.Height; } var radius = Math.Sqrt(Math.Pow(width, 2) + Math.Pow(height, 2)); RippleSize = 2 * radius * RippleAssist.GetRippleSizeMultiplier(this); }
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { var point = e.GetPosition(this); if (RippleAssist.GetIsCentered(this)) { var innerContent = (Content as FrameworkElement); if (innerContent != null) { var position = innerContent.TransformToAncestor(this) .Transform(new Point(0, 0)); RippleX = position.X + innerContent.ActualWidth / 2 - RippleSize / 2; RippleY = position.Y + innerContent.ActualHeight / 2 - RippleSize / 2; } else { RippleX = ActualWidth / 2 - RippleSize / 2; RippleY = ActualHeight / 2 - RippleSize / 2; } } else { RippleX = point.X - RippleSize / 2; RippleY = point.Y - RippleSize / 2; } if (!RippleAssist.GetIsDisabled(this)) { VisualStateManager.GoToState(this, TemplateStateNormal, false); VisualStateManager.GoToState(this, TemplateStateMousePressed, true); PressedInstances.Add(this); } base.OnPreviewMouseLeftButtonDown(e); }