| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- using System;
- using System.ComponentModel;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- namespace Muchinfo.DataPager.Base
- {
- public class MuchinfoRoutedEventArgs : RoutedEventArgs
- {
- public MuchinfoRoutedEventArgs()
- {
- }
- public MuchinfoRoutedEventArgs(RoutedEvent routedEvent)
- : this(routedEvent, null)
- {
- }
- public MuchinfoRoutedEventArgs(RoutedEvent routedEvent, object source)
- : base(routedEvent, source)
- {
- }
- }
- public class MuchinfoPagerNumberRadioButton : RadioButton
- {
- public static readonly DependencyProperty CornerRadiusProperty;
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- public static readonly DependencyProperty InnerCornerRadiusProperty;
- public static readonly DependencyProperty IsBackgroundVisibleProperty;
- public static readonly RoutedEvent ActivateEvent;
- public event EventHandler<MuchinfoRoutedEventArgs> Activate
- {
- add
- {
- base.AddHandler(MuchinfoPagerNumberRadioButton.ActivateEvent, value);
- }
- remove
- {
- base.RemoveHandler(MuchinfoPagerNumberRadioButton.ActivateEvent, value);
- }
- }
- public CornerRadius CornerRadius
- {
- get
- {
- return (CornerRadius)base.GetValue(MuchinfoPagerNumberRadioButton.CornerRadiusProperty);
- }
- set
- {
- base.SetValue(MuchinfoPagerNumberRadioButton.CornerRadiusProperty, value);
- }
- }
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- public CornerRadius InnerCornerRadius
- {
- get
- {
- return (CornerRadius)base.GetValue(MuchinfoPagerNumberRadioButton.InnerCornerRadiusProperty);
- }
- set
- {
- base.SetValue(MuchinfoPagerNumberRadioButton.InnerCornerRadiusProperty, value);
- }
- }
- [Browsable(false)]
- public bool IsBackgroundVisible
- {
- get
- {
- return (bool)base.GetValue(MuchinfoPagerNumberRadioButton.IsBackgroundVisibleProperty);
- }
- set
- {
- base.SetValue(MuchinfoPagerNumberRadioButton.IsBackgroundVisibleProperty, value);
- }
- }
- static MuchinfoPagerNumberRadioButton()
- {
- MuchinfoPagerNumberRadioButton.CornerRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(MuchinfoPagerNumberRadioButton), new PropertyMetadata(new PropertyChangedCallback(MuchinfoPagerNumberRadioButton.OnCornerRadiusChanged)));
- MuchinfoPagerNumberRadioButton.InnerCornerRadiusProperty = DependencyProperty.Register("InnerCornerRadius", typeof(CornerRadius), typeof(MuchinfoPagerNumberRadioButton), new PropertyMetadata());
- MuchinfoPagerNumberRadioButton.IsBackgroundVisibleProperty = DependencyProperty.Register("IsBackgroundVisible", typeof(bool), typeof(MuchinfoPagerNumberRadioButton), new PropertyMetadata(true, new PropertyChangedCallback(MuchinfoPagerNumberRadioButton.OnIsBackgroundVisiblePropertyChanged)));
- MuchinfoPagerNumberRadioButton.ActivateEvent = EventManager.RegisterRoutedEvent("Activate", RoutingStrategy.Bubble, typeof(EventHandler<MuchinfoRoutedEventArgs>), typeof(MuchinfoPagerNumberRadioButton));
- FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(MuchinfoPagerNumberRadioButton), new FrameworkPropertyMetadata(typeof(MuchinfoPagerNumberRadioButton)));
- }
- public override void OnApplyTemplate()
- {
- base.OnApplyTemplate();
- this.UpdateVisualStates();
- this.UpdateBackgroundVisibility();
- }
- internal void UpdateVisualStates()
- {
- if (!base.IsEnabled)
- {
- if (base.IsChecked == true)
- {
- VisualStateManager.GoToState(this, "DisabledChecked", true);
- }
- else
- {
- VisualStateManager.GoToState(this, "Disabled", true);
- }
- }
- else
- {
- if (base.IsPressed)
- {
- VisualStateManager.GoToState(this, "Pressed", true);
- }
- else
- {
- if (base.IsMouseOver)
- {
- if (base.IsChecked == true)
- {
- VisualStateManager.GoToState(this, "MouseOverChecked", true);
- }
- else
- {
- VisualStateManager.GoToState(this, "MouseOver", true);
- }
- }
- else
- {
- VisualStateManager.GoToState(this, "Normal", true);
- }
- }
- }
- if (base.IsChecked == true)
- {
- VisualStateManager.GoToState(this, "Checked", true);
- }
- else
- {
- if (base.IsChecked == false)
- {
- VisualStateManager.GoToState(this, "Unchecked", true);
- }
- else
- {
- if (!VisualStateManager.GoToState(this, "Indeterminate", true))
- {
- VisualStateManager.GoToState(this, "Unchecked", true);
- }
- }
- }
- if (base.IsFocused && base.IsEnabled)
- {
- VisualStateManager.GoToState(this, "Focused", true);
- }
- else
- {
- VisualStateManager.GoToState(this, "Unfocused", true);
- }
- if (this.IsBackgroundVisible || base.IsMouseOver || base.IsPressed)
- {
- VisualStateManager.GoToState(this, "BackgroundVisible", true);
- }
- else
- {
- VisualStateManager.GoToState(this, "BackgroundHidden", true);
- }
- if (this.IsBackgroundVisible)
- {
- VisualStateManager.GoToState(this, "BackgroundIsVisible", false);
- return;
- }
- VisualStateManager.GoToState(this, "BackgroundIsHidden", false);
- }
- internal void UpdateBackgroundVisibility()
- {
- this.UpdateVisualStates();
- }
- internal void OnToggleInternal()
- {
- this.OnToggle();
- }
- protected internal virtual void OnActivate()
- {
- base.RaiseEvent(new MuchinfoRoutedEventArgs(MuchinfoPagerNumberRadioButton.ActivateEvent, this));
- }
- protected override void OnToggle()
- {
- base.OnToggle();
- this.OnActivate();
- //if (base.IsChecked == true)
- //{
- // TraceMonitor.TrackAtomicFeature(this, "Checked");
- // return;
- //}
- //if (base.IsChecked == false)
- //{
- // TraceMonitor.TrackAtomicFeature(this, "Unchecked");
- //}
- }
- protected override void OnMouseEnter(MouseEventArgs e)
- {
- base.OnMouseEnter(e);
- this.UpdateVisualStates();
- this.UpdateBackgroundVisibility();
- }
- protected override void OnMouseLeave(MouseEventArgs e)
- {
- base.OnMouseLeave(e);
- this.UpdateVisualStates();
- this.UpdateBackgroundVisibility();
- }
- protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
- {
- base.OnMouseLeftButtonUp(e);
- this.UpdateVisualStates();
- this.UpdateBackgroundVisibility();
- }
- protected override void OnLostFocus(RoutedEventArgs e)
- {
- base.OnLostFocus(e);
- this.UpdateBackgroundVisibility();
- }
- protected override void OnGotFocus(RoutedEventArgs e)
- {
- base.OnGotFocus(e);
- this.UpdateBackgroundVisibility();
- }
- private static void OnCornerRadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- MuchinfoPagerNumberRadioButton radRadioButton = d as MuchinfoPagerNumberRadioButton;
- CornerRadius cornerRadius = (CornerRadius)e.NewValue;
- if (radRadioButton != null)
- {
- radRadioButton.InnerCornerRadius = new CornerRadius(Math.Max(0.0, cornerRadius.TopLeft - 1.0), Math.Max(0.0, cornerRadius.TopRight - 1.0), Math.Max(0.0, cornerRadius.BottomRight - 1.0), Math.Max(0.0, cornerRadius.BottomLeft - 1.0));
- }
- }
- private static void OnIsBackgroundVisiblePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- MuchinfoPagerNumberRadioButton radRadioButton = d as MuchinfoPagerNumberRadioButton;
- }
- }
- }
|