using System; using System.Collections.Generic; 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.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace ZitiDesktopEdge { /// /// Interaction logic for StyledButton.xaml /// public partial class StyledButton : UserControl { public delegate void ClickAction(); public event ClickAction OnClick; private string _label = ""; private string bgColor = "#0069FF"; public string BgColor { get { return bgColor; } set { bgColor = value; ButtonBgColor.Color = (Color)ColorConverter.ConvertFromString(bgColor); } } public string Label { get { return _label; } set { this._label = value; ButtonLabel.Content = this._label; } } public StyledButton() { InitializeComponent(); } /// /// When the button area is entered slowly make it slightly opaque /// /// The button object /// The mouse event private void Hover(object sender, MouseEventArgs e) { ButtonBgDarken.Opacity = 0.0; ButtonBgDarken.BeginAnimation(Grid.OpacityProperty, new DoubleAnimation(0.2, TimeSpan.FromSeconds(.3))); } /// /// When the mouse leaves the button ara snap the opacity back to full /// /// The button object /// The mouse event private void Leave(object sender, MouseEventArgs e) { ButtonBgDarken.Opacity = 0.2; ButtonBgDarken.BeginAnimation(Grid.OpacityProperty, new DoubleAnimation(0.0, TimeSpan.FromSeconds(.3))); } /// /// Change the color to visualize a click event /// /// /// private void Down(object sender, MouseButtonEventArgs e) { // ButtonBgColor.Color = Color.FromRgb(126, 180, 255); } /// /// Execute the click operation /// /// /// private void DoClick(object sender, MouseButtonEventArgs e) { this.OnClick?.Invoke(); } } }