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 { /// /// DraggableWindowHeader.xaml 的交互逻辑 /// 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 } }