using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.SharedUI.Helpers;
using Tango.Touch.Controls;
namespace Tango.Touch.Components
{
[ContentProperty(nameof(Content))]
[TemplatePart(Name = PART_EllipseName, Type = typeof(Ellipse))]
[TemplatePart(Name = PART_ScaleName, Type = typeof(ScaleTransform))]
public class Ripple : Control
{
private const String PART_ScaleName = "PART_scale";
private const String PART_EllipseName = "PART_ellipse";
private ScaleTransform _scale;
private Ellipse _ellipse;
private bool _isAnimating;
public UIElement Content
{
get { return (UIElement)GetValue(ContentProperty); }
set { SetValue(ContentProperty, value); }
}
public static readonly DependencyProperty ContentProperty =
DependencyProperty.Register("Content", typeof(UIElement), typeof(Ripple), new PropertyMetadata(null));
public CornerRadius CornerRadius
{
get { return (CornerRadius)GetValue(CornerRadiusProperty); }
set { SetValue(CornerRadiusProperty, value); }
}
public static readonly DependencyProperty CornerRadiusProperty =
DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(Ripple), new PropertyMetadata(new CornerRadius()));
public Brush RippleBrush
{
get { return (Brush)GetValue(RippleBrushProperty); }
set { SetValue(RippleBrushProperty, value); }
}
public static readonly DependencyProperty RippleBrushProperty =
DependencyProperty.Register("RippleBrush", typeof(Brush), typeof(Ripple), new PropertyMetadata(null));
public ScrollViewer SynchedScrollViewer
{
get { return (ScrollViewer)GetValue(SynchedScrollViewerProperty); }
set { SetValue(SynchedScrollViewerProperty, value); }
}
public static readonly DependencyProperty SynchedScrollViewerProperty =
DependencyProperty.Register("SynchedScrollViewer", typeof(ScrollViewer), typeof(Ripple), new PropertyMetadata(null));
public double RippleFactor
{
get { return (double)GetValue(RippleFactorProperty); }
set { SetValue(RippleFactorProperty, value); }
}
public static readonly DependencyProperty RippleFactorProperty =
DependencyProperty.Register("RippleFactor", typeof(double), typeof(Ripple), new PropertyMetadata(5.0));
public bool Centered
{
get { return (bool)GetValue(CenteredProperty); }
set { SetValue(CenteredProperty, value); }
}
public static readonly DependencyProperty CenteredProperty =
DependencyProperty.Register("Centered", typeof(bool), typeof(Ripple), new PropertyMetadata(false));
public bool Disabled
{
get { return (bool)GetValue(DisabledProperty); }
set { SetValue(DisabledProperty, value); }
}
public static readonly DependencyProperty DisabledProperty =
DependencyProperty.Register("Disabled", typeof(bool), typeof(Ripple), new PropertyMetadata(false,(d,e) => (d as Ripple).OnDisabledChanged()));
private void OnDisabledChanged()
{
if (Disabled)
{
CancelRipple(true);
}
}
#region Attached Properties
#region PreventRipple
///
/// Determines whether an element is a dropable target by the drag and drop service.
///
public static readonly DependencyProperty PreventRippleProperty =
DependencyProperty.RegisterAttached("PreventRipple",
typeof(bool), typeof(Ripple),
new FrameworkPropertyMetadata(false));
///
/// Sets the PreventRipple attached property.
///
/// The element.
/// if set to true [value].
public static void SetPreventRipple(FrameworkElement element, bool value)
{
element.SetValue(PreventRippleProperty, value);
}
///
/// Gets the PreventRipple attached property.
///
/// The element.
///
public static bool GetPreventRipple(FrameworkElement element)
{
if (element != null)
{
return (bool)element.GetValue(PreventRippleProperty);
}
else
{
return false;
}
}
#endregion
#endregion
static Ripple()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Ripple), new FrameworkPropertyMetadata(typeof(Ripple)));
}
public Ripple()
{
this.Loaded += Ripple_Loaded;
}
private void Ripple_Loaded(object sender, RoutedEventArgs e)
{
if (SynchedScrollViewer != null)
{
SynchedScrollViewer.ScrollChanged += (_, __) => CancelRipple(true);
}
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_scale = GetTemplateChild(PART_ScaleName) as ScaleTransform;
_ellipse = GetTemplateChild(PART_EllipseName) as Ellipse;
FrameworkElement parent = this.FindAncestor