123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using ComeCapture.Models;
-
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
-
- namespace ComeCapture.Controls
- {
- public class ToolButton : RadioButton
- {
- static ToolButton()
- {
- DefaultStyleKeyProperty.OverrideMetadata(
- typeof(ToolButton),
- new FrameworkPropertyMetadata(typeof(ToolButton))
- );
- }
-
- #region 覆写点击事件(可弹起)
-
- protected override void OnClick()
- {
- if (IsImageEditBar)
- {
- switch (Tool)
- {
- case Tool.Revoke:
- JieTuWindow.Current.OnRevoke();
- break;
-
- case Tool.Save:
- JieTuWindow.Current.OnSave();
- break;
-
- case Tool.Cancel:
- JieTuWindow.Current.OnCancel();
- break;
-
- case Tool.OK:
- JieTuWindow.Current.OnOK();
- break;
-
- default:
- IsChecked = !IsChecked;
- SizeColorBar.Current.Selected = IsChecked == true ? Tool : Tool.Null;
- break;
- }
- }
- else
- {
- if (IsChecked == false)
- {
- IsChecked = true;
- if (LineColor != null)
- {
- SizeColorBar.Current.ChangeColor(LineColor);
- }
- }
- }
- }
-
- #endregion 覆写点击事件(可弹起)
-
- #region Tool DependencyProperty
-
- public Tool Tool
- {
- get => (Tool)GetValue(ToolProperty);
- set => SetValue(ToolProperty, value);
- }
-
- public static readonly DependencyProperty ToolProperty =
- DependencyProperty.Register("Tool", typeof(Tool), typeof(ToolButton),
- new PropertyMetadata(Tool.Null, new PropertyChangedCallback(ToolButton.OnToolPropertyChanged)));
-
- private static void OnToolPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
- {
- if (obj is ToolButton)
- {
- (obj as ToolButton).OnToolValueChanged();
- }
- }
-
- protected void OnToolValueChanged()
- {
- }
-
- #endregion Tool DependencyProperty
-
- #region IsImageEditBar DependencyProperty
-
- public bool IsImageEditBar
- {
- get => (bool)GetValue(IsImageEditBarProperty);
- set => SetValue(IsImageEditBarProperty, value);
- }
-
- public static readonly DependencyProperty IsImageEditBarProperty =
- DependencyProperty.Register("IsImageEditBar", typeof(bool), typeof(ToolButton),
- new PropertyMetadata(false, new PropertyChangedCallback(ToolButton.OnIsImageEditBarPropertyChanged)));
-
- private static void OnIsImageEditBarPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
- {
- if (obj is ToolButton)
- {
- (obj as ToolButton).OnIsImageEditBarValueChanged();
- }
- }
-
- protected void OnIsImageEditBarValueChanged()
- {
- }
-
- #endregion IsImageEditBar DependencyProperty
-
- #region LineColor DependencyProperty
-
- public SolidColorBrush LineColor
- {
- get => (SolidColorBrush)GetValue(LineColorProperty);
- set => SetValue(LineColorProperty, value);
- }
-
- public static readonly DependencyProperty LineColorProperty =
- DependencyProperty.Register("LineColor", typeof(SolidColorBrush), typeof(ToolButton),
- new PropertyMetadata(null, new PropertyChangedCallback(ToolButton.OnLineColorPropertyChanged)));
-
- private static void OnLineColorPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
- {
- if (obj is ToolButton)
- {
- (obj as ToolButton).OnLineColorValueChanged();
- }
- }
-
- protected void OnLineColorValueChanged()
- {
- }
-
- #endregion LineColor DependencyProperty
- }
- }
|