| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- using MuchInfo.Chart.Infrastructure.Helpers;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Input;
- using System.Windows.Media;
- namespace MuchInfo.Chart.Infrastructure.Controls
- {
- /// <summary>
- /// DraggableWindowHeader.xaml 的交互逻辑
- /// </summary>
- public partial class DraggableWindowHeader : UserControl
- {
- #region Fields
- private Point _currentPoint;
- private Popup _popup;
- private Point _popupPoint;
- #endregion Fields
- #region Constructors
- public DraggableWindowHeader()
- {
- this.InitializeComponent();
- }
- #endregion Constructors
- #region Delegates
- public delegate void DeleteClickedEventHandler();
- #endregion Delegates
- #region Events
- public event DraggableWindowHeader.DeleteClickedEventHandler DeleteClicked;
- #endregion Events
- #region Properties
- #region Public Properties
- public CornerRadius CornerRadius
- {
- get
- {
- return this.borderMain.CornerRadius;
- }
- set
- {
- this.borderMain.CornerRadius = value;
- }
- }
- public Brush DeleteButtonForeColor
- {
- get
- {
- return this.borderDelete.BorderBrush;
- }
- set
- {
- this.borderDelete.BorderBrush = value;
- this.txtDelete.Foreground = value;
- }
- }
- public Brush HeaderBackGround
- {
- get
- {
- return this.borderMain.Background;
- }
- set
- {
- this.borderMain.Background = value;
- }
- }
- public Brush HeaderBorderColor
- {
- get
- {
- return this.borderMain.BorderBrush;
- }
- set
- {
- this.borderMain.BorderBrush = value;
- }
- }
- public double HeaderBorderThickness
- {
- get
- {
- return this.borderMain.BorderThickness.Left;
- }
- set
- {
- this.borderMain.BorderThickness = new Thickness(value, value, value, 0.0);
- }
- }
- public ImageSource HeaderImage
- {
- get
- {
- return this.headerIcon.Source;
- }
- set
- {
- bool flag = value == null;
- if (flag)
- {
- this.headerIcon.Visibility = Visibility.Collapsed;
- }
- else
- {
- this.headerIcon.Visibility = Visibility.Visible;
- }
- this.headerIcon.Source = value;
- }
- }
- public Panel RootPanel { get; set; }
- public string HeaderText
- {
- get
- {
- return this.txtHeader.Text;
- }
- set
- {
- this.txtHeader.Text = value;
- }
- }
- public bool ShowDeleteButton
- {
- get
- {
- return this.borderDelete.Visibility == 0;
- }
- set
- {
- this.borderDelete.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
- }
- }
- #endregion Public Properties
- #endregion Properties
- #region Methods
- #region Protected Methods
- protected virtual void OnDeleteClicked()
- {
- var handler = DeleteClicked;
- if (handler != null) handler();
- }
- #endregion Protected Methods
- #region Private Methods
- private void borderDelete_MouseEnter(object sender, MouseEventArgs e)
- {
- this.txtDelete.Foreground = new SolidColorBrush(ColorHelper.Firebrick);
- }
- private void borderDelete_MouseLeave(object sender, MouseEventArgs e)
- {
- this.txtDelete.Foreground = this.borderDelete.BorderBrush;
- }
- private void borderDelete_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- OnDeleteClicked();
- }
- private void borderGrab_LostMouseCapture(object sender, MouseEventArgs e)
- {
- this._popup = null;
- }
- private void borderGrab_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- this._popup = this.GetPopup(this);
- bool flag = this._popup != null;
- if (flag)
- {
- this._currentPoint = e.GetPosition(RootPanel);
- this._popupPoint = new Point(this._popup.HorizontalOffset, this._popup.VerticalOffset);
- this.borderGrab.CaptureMouse();
- }
- }
- private void borderGrab_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- bool flag = this._popup != null;
- if (flag)
- {
- this.ShowPopup(e);
- this._popup = null;
- this.borderGrab.ReleaseMouseCapture();
- }
- }
- private void borderGrab_MouseMove(object sender, MouseEventArgs e)
- {
- bool flag = this._popup != null;
- if (flag)
- {
- this.ShowPopup(e);
- }
- }
- private Popup GetPopup(FrameworkElement aControl)
- {
- bool flag = aControl.Parent != null && aControl.Parent is Popup;
- Popup result;
- if (flag)
- {
- var popup = (Popup)aControl.Parent;
- result = popup;
- }
- else
- {
- flag = (aControl.Parent != null && aControl.Parent is FrameworkElement);
- result = flag ? this.GetPopup((FrameworkElement)aControl.Parent) : null;
- }
- return result;
- }
- private void ShowPopup(MouseEventArgs e)
- {
- var position = e.GetPosition(RootPanel);
- var point = new Point(position.X - this._currentPoint.X + this._popupPoint.X, position.Y - this._currentPoint.Y + this._popupPoint.Y);
- this._popup.VerticalOffset = (point.Y);
- this._popup.HorizontalOffset = (point.X);
- GeometryHelper.EnsureControlInApplication(this._popup, RootPanel);
- }
- #endregion Private Methods
- #endregion Methods
- }
- }
|