// ----------------------------------------------------------------------- // // Copyright 2013 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Controls { using System; public class Button : ContentControl { public static readonly RoutedEvent ClickEvent = RoutedEvent.Register("Click", RoutingStrategy.Bubble); static Button() { FocusableProperty.OverrideDefaultValue(typeof(Button), true); } public Button() { this.PointerPressed += (s, e) => { this.Classes.Add(":pressed"); e.Device.Capture(this); }; this.PointerReleased += (s, e) => { e.Device.Capture(null); this.Classes.Remove(":pressed"); if (this.Classes.Contains(":pointerover")) { RoutedEventArgs click = new RoutedEventArgs(ClickEvent, this); this.RaiseEvent(click); } }; } public event EventHandler Click { add { this.AddHandler(ClickEvent, value); } remove { this.RemoveHandler(ClickEvent, value); } } } }