12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- namespace ComPDFKit.Controls.Common
- {
- public class HomePageButton : Button
- {
- public static readonly DependencyProperty IsToggledProperty =
- DependencyProperty.Register("IsToggled", typeof(bool), typeof(HomePageButton), new PropertyMetadata(false));
- public bool IsToggled
- {
- get { return (bool)GetValue(IsToggledProperty); }
- set { SetValue(IsToggledProperty, value); }
- }
- public static readonly RoutedEvent ToggledEvent =
- EventManager.RegisterRoutedEvent("Toggled", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(HomePageButton));
- public event RoutedEventHandler Toggled
- {
- add { AddHandler(ToggledEvent, value); }
- remove { RemoveHandler(ToggledEvent, value); }
- }
- public HomePageButton()
- {
- Click += HomePageButton_Click; ;
- }
- public class QueryLockEventArgs : EventArgs
- {
- public bool CanLock { get; set; }
- }
- public delegate bool QueryLockHandler(object sender, QueryLockEventArgs e);
- public event QueryLockHandler QueryLock;
- private void HomePageButton_Click(object sender, RoutedEventArgs e)
- {
- if (QueryLock?.Invoke(this, new QueryLockEventArgs()) == false)
- {
- IsToggled = !IsToggled;
- RaiseToggledEvent();
- }
- }
- private void RaiseToggledEvent()
- {
- RoutedEventArgs newEventArgs = new RoutedEventArgs(ToggledEvent);
- RaiseEvent(newEventArgs);
- }
- }
- }
|