diff --git a/HandyControl/Controls/Attach/PanelElement.cs b/HandyControl/Controls/Attach/PanelElement.cs index f1788378..05578452 100644 --- a/HandyControl/Controls/Attach/PanelElement.cs +++ b/HandyControl/Controls/Attach/PanelElement.cs @@ -15,12 +15,12 @@ namespace HandyControl.Controls { var collection = Interaction.GetBehaviors(panel); var oldBehavior = GetTempFluidMoveBehavior(panel); - collection.Remove(oldBehavior); + collection.ItemRemoved(oldBehavior); panel.SetCurrentValue(TempFluidMoveBehaviorProperty, DependencyProperty.UnsetValue); if (e.NewValue is FluidMoveBehavior behavior) { - collection.Add(behavior); + collection.ItemAdded(behavior); SetTempFluidMoveBehavior(panel, behavior); } } diff --git a/HandyControl/Controls/Image/ImageViewer.cs b/HandyControl/Controls/Image/ImageViewer.cs index 4422a932..08ffd909 100644 --- a/HandyControl/Controls/Image/ImageViewer.cs +++ b/HandyControl/Controls/Image/ImageViewer.cs @@ -16,7 +16,7 @@ using Microsoft.Win32; namespace HandyControl.Controls { - [TemplatePart(Name = ElementGridMain, Type = typeof(Grid))] + [TemplatePart(Name = ElementPanelMain, Type = typeof(Panel))] [TemplatePart(Name = ElementCanvasSmallImg, Type = typeof(Canvas))] [TemplatePart(Name = ElementBorderMove, Type = typeof(Border))] [TemplatePart(Name = ElementBorderBottom, Type = typeof(Border))] @@ -25,7 +25,7 @@ namespace HandyControl.Controls { #region Constants - private const string ElementGridMain = "PART_GridMain"; + private const string ElementPanelMain = "PART_PanelMain"; private const string ElementCanvasSmallImg = "PART_CanvasSmallImg"; @@ -52,7 +52,7 @@ namespace HandyControl.Controls Filter = $"{Lang.PngImg}|*.png" }; - private Grid _gridMain; + private Panel _panelMain; private Canvas _canvasSmallImg; @@ -401,7 +401,7 @@ namespace HandyControl.Controls base.OnApplyTemplate(); - _gridMain = GetTemplateChild(ElementGridMain) as Grid; + _panelMain = GetTemplateChild(ElementPanelMain) as Panel; _canvasSmallImg = GetTemplateChild(ElementCanvasSmallImg) as Canvas; _borderMove = GetTemplateChild(ElementBorderMove) as Border; _imageMain = GetTemplateChild(ElementImageMain) as Image; @@ -610,7 +610,7 @@ namespace HandyControl.Controls private void ImageMain_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { - _imgMouseDownPoint = Mouse.GetPosition(_gridMain); + _imgMouseDownPoint = Mouse.GetPosition(_panelMain); _imgMouseDownMargin = ImageMargin; _imgIsMouseLeftButtonDown = true; } @@ -705,7 +705,7 @@ namespace HandyControl.Controls ImageScale = tempScale; - var posCanvas = Mouse.GetPosition(_gridMain); + var posCanvas = Mouse.GetPosition(_panelMain); var posImg = new Point(posCanvas.X - _imgActualMargin.Left, posCanvas.Y - _imgActualMargin.Top); var marginX = .5 * _scaleInternalWidth; @@ -789,7 +789,7 @@ namespace HandyControl.Controls /// private void MoveImg() { - _imgCurrentPoint = Mouse.GetPosition(_gridMain); + _imgCurrentPoint = Mouse.GetPosition(_panelMain); ShowCloseButton = _imgCurrentPoint.Y < 200; ShowBorderBottom = _imgCurrentPoint.Y > ActualHeight - 200; diff --git a/HandyControl/Controls/Input/PasswordBox.cs b/HandyControl/Controls/Input/PasswordBox.cs index 8d7708e2..2bb0c38f 100644 --- a/HandyControl/Controls/Input/PasswordBox.cs +++ b/HandyControl/Controls/Input/PasswordBox.cs @@ -165,9 +165,6 @@ namespace HandyControl.Controls - private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) - { - VerifyData(); - } + private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) => VerifyData(); } } \ No newline at end of file diff --git a/HandyControl/Controls/Input/SearchBar.cs b/HandyControl/Controls/Input/SearchBar.cs index d34a3557..3b13e84e 100644 --- a/HandyControl/Controls/Input/SearchBar.cs +++ b/HandyControl/Controls/Input/SearchBar.cs @@ -7,7 +7,7 @@ using HandyControl.Interactivity; namespace HandyControl.Controls { - public class SearchBar : TextBox + public class SearchBar : TextBox, ICommandSource { public SearchBar() { @@ -51,6 +51,16 @@ namespace HandyControl.Controls { Info = Text }); + + if (Command == null) return; + if (Command is RoutedCommand command) + { + command.Execute(CommandParameter, CommandTarget); + } + else + { + Command.Execute(CommandParameter); + } } /// @@ -67,5 +77,54 @@ namespace HandyControl.Controls get => (bool)GetValue(IsRealTimeProperty); set => SetValue(IsRealTimeProperty, value); } + + public static readonly DependencyProperty CommandProperty = DependencyProperty.Register( + "Command", typeof(ICommand), typeof(SearchBar), new PropertyMetadata(default(ICommand), OnCommandChanged)); + + private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var ctl = (SearchBar)d; + if (e.OldValue is ICommand oldCommand) + { + oldCommand.CanExecuteChanged -= ctl.CanExecuteChanged; + } + if (e.NewValue is ICommand newCommand) + { + newCommand.CanExecuteChanged += ctl.CanExecuteChanged; + } + } + + public ICommand Command + { + get => (ICommand) GetValue(CommandProperty); + set => SetValue(CommandProperty, value); + } + + public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register( + "CommandParameter", typeof(object), typeof(SearchBar), new PropertyMetadata(default(object))); + + public object CommandParameter + { + get => GetValue(CommandParameterProperty); + set => SetValue(CommandParameterProperty, value); + } + + public static readonly DependencyProperty CommandTargetProperty = DependencyProperty.Register( + "CommandTarget", typeof(IInputElement), typeof(SearchBar), new PropertyMetadata(default(IInputElement))); + + public IInputElement CommandTarget + { + get => (IInputElement) GetValue(CommandTargetProperty); + set => SetValue(CommandTargetProperty, value); + } + + private void CanExecuteChanged(object sender, EventArgs e) + { + if (Command == null) return; + + IsEnabled = Command is RoutedCommand command + ? command.CanExecute(CommandParameter, CommandTarget) + : Command.CanExecute(CommandParameter); + } } } diff --git a/HandyControl/Controls/Input/WatermarkTextBox.cs b/HandyControl/Controls/Input/WatermarkTextBox.cs index 56586688..dbdf51bb 100644 --- a/HandyControl/Controls/Input/WatermarkTextBox.cs +++ b/HandyControl/Controls/Input/WatermarkTextBox.cs @@ -1,36 +1,15 @@ using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; namespace HandyControl.Controls { - [TemplatePart(Name = ElementContentName, Type = typeof(ContentControl))] - public class WatermarkTextBox : TextBox + internal class WatermarkTextBox : TextBox { - #region Constants - - private const string ElementContentName = "PART_Watermark"; - - #endregion Constants - - #region Data - - private ContentControl _elementContent; - - #endregion Data - #region Public Properties #region Watermark public static readonly DependencyProperty WatermarkProperty = DependencyProperty.Register( - "Watermark", typeof(object), typeof(WatermarkTextBox), new PropertyMetadata(default(object), OnWatermarkChanged)); - - private static void OnWatermarkChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var ctl = (WatermarkTextBox) d; - ctl.OnWatermarkChanged(); - } + "Watermark", typeof(object), typeof(WatermarkTextBox), new PropertyMetadata(default(object))); public object Watermark { @@ -42,26 +21,6 @@ namespace HandyControl.Controls #endregion Public Properties - public override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - _elementContent = GetTemplateChild(ElementContentName) as ContentControl; - _elementContent?.SetBinding(ContentControl.ContentProperty, new Binding(WatermarkProperty.Name) {Source = this}); - - OnWatermarkChanged(); - } - - private void OnWatermarkChanged() - { - if (_elementContent == null) return; - if (Watermark is Control watermarkControl) - { - watermarkControl.IsTabStop = false; - watermarkControl.IsHitTestVisible = false; - } - } - protected override void OnGotFocus(RoutedEventArgs e) { base.OnGotFocus(e); diff --git a/HandyControl/Controls/Other/Growl.cs b/HandyControl/Controls/Other/Growl.cs index f6ec5b4c..ed274460 100644 --- a/HandyControl/Controls/Other/Growl.cs +++ b/HandyControl/Controls/Other/Growl.cs @@ -4,7 +4,6 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; -using System.Windows.Media.Animation; using System.Windows.Threading; using HandyControl.Data; using HandyControl.Interactivity; @@ -43,11 +42,6 @@ namespace HandyControl.Controls private int _waitTime = 6; - /// - /// 消息容器 - /// - public static Panel GrowlPanel { get; set; } - /// /// 计数 /// @@ -65,14 +59,21 @@ namespace HandyControl.Controls CommandBindings.Add(new CommandBinding(ControlCommands.Close, ButtonClose_OnClick)); CommandBindings.Add(new CommandBinding(ControlCommands.Cancel, ButtonCancel_OnClick)); CommandBindings.Add(new CommandBinding(ControlCommands.Confirm, ButtonOk_OnClick)); - - MouseEnter += Growl_MouseEnter; - MouseLeave += Growl_MouseLeave; } - private void Growl_MouseLeave(object sender, MouseEventArgs e) => _buttonClose.Collapse(); + protected override void OnMouseEnter(MouseEventArgs e) + { + base.OnMouseEnter(e); - private void Growl_MouseEnter(object sender, MouseEventArgs e) => _buttonClose.Show(_showCloseButton); + _buttonClose.Show(_showCloseButton); + } + + protected override void OnMouseLeave(MouseEventArgs e) + { + base.OnMouseLeave(e); + + _buttonClose.Collapse(); + } public override void OnApplyTemplate() { @@ -93,6 +94,11 @@ namespace HandyControl.Controls private Func ActionBeforeClose { get; set; } + /// + /// 消息容器 + /// + public static Panel GrowlPanel { get; set; } + internal static readonly DependencyProperty CancelStrProperty = DependencyProperty.Register( "CancelStr", typeof(string), typeof(Growl), new PropertyMetadata(default(string))); @@ -120,7 +126,7 @@ namespace HandyControl.Controls public static readonly DependencyProperty GrowlParentProperty = DependencyProperty.RegisterAttached( "GrowlParent", typeof(bool), typeof(Growl), new PropertyMetadata(ValueBoxes.FalseBox, (o, args) => { - if (o is Panel panel) + if ((bool)args.NewValue && o is Panel panel) { SetGrowlPanel(panel); } @@ -226,14 +232,8 @@ namespace HandyControl.Controls menuItem } }; - var behavior = new FluidMoveBehavior - { - AppliesTo = FluidMoveScope.Children, - Duration = new Duration(TimeSpan.FromMilliseconds(400)), - EaseY = new PowerEase() - }; - var collection = Interaction.GetBehaviors(GrowlPanel); - collection.Add(behavior); + + PanelElement.SetFluidMoveBehavior(GrowlPanel, ResourceHelper.GetResource(ResourceToken.BehaviorXY400)); } private void Update() @@ -451,7 +451,13 @@ namespace HandyControl.Controls var transform = new TranslateTransform(); _gridMain.RenderTransform = transform; var animation = AnimationHelper.CreateAnimation(MaxWidth); - animation.Completed += delegate { GrowlPanel.Children.Remove(this); }; + animation.Completed += (s, e) => + { + if (Parent is Panel panel) + { + panel.Children.Remove(this); + } + }; transform.BeginAnimation(TranslateTransform.XProperty, animation); } diff --git a/HandyControl/Controls/Slider/CompareSlider.cs b/HandyControl/Controls/Slider/CompareSlider.cs index 07bd98af..23ff9a43 100644 --- a/HandyControl/Controls/Slider/CompareSlider.cs +++ b/HandyControl/Controls/Slider/CompareSlider.cs @@ -22,38 +22,6 @@ namespace HandyControl.Controls { get => GetValue(SourceContentProperty); set => SetValue(SourceContentProperty, value); - } - - //private bool _isLoaded; - - //private double _tempValue; - - //public CompareSlider() - //{ - // //Loaded += delegate - // //{ - // // if (_isLoaded) return; - // // _isLoaded = true; - // // Value = _tempValue; - // //}; - //} - - ////protected override void OnRender(DrawingContext drawingContext) - ////{ - //// base.OnRender(drawingContext); - - //// Value = _tempValue; - ////} - - ////public override void OnApplyTemplate() - ////{ - //// base.OnApplyTemplate(); - //// _tempValue = Value; - //// Value = Orientation == Orientation.Horizontal ? Maximum : 0; - //// if (_isLoaded) - //// { - //// Value = _tempValue; - //// } - ////} + } } } \ No newline at end of file diff --git a/HandyControl/Controls/Window/ImageBrowser.cs b/HandyControl/Controls/Window/ImageBrowser.cs index f711ff54..c9741b62 100644 --- a/HandyControl/Controls/Window/ImageBrowser.cs +++ b/HandyControl/Controls/Window/ImageBrowser.cs @@ -12,13 +12,13 @@ namespace HandyControl.Controls /// /// 图片浏览器 /// - [TemplatePart(Name = ElementGridTop, Type = typeof(Grid))] + [TemplatePart(Name = ElementPanelTop, Type = typeof(Panel))] [TemplatePart(Name = ElementImageViewer, Type = typeof(ImageViewer))] public class ImageBrowser : Window { #region Constants - private const string ElementGridTop = "PART_GridTop"; + private const string ElementPanelTop = "PART_PanelTop"; private const string ElementImageViewer = "PART_ImageViewer"; @@ -26,7 +26,7 @@ namespace HandyControl.Controls #region Data - private Grid _gridTop; + private Panel _panelTop; private ImageViewer _imageViewer; @@ -82,9 +82,9 @@ namespace HandyControl.Controls public override void OnApplyTemplate() { - if (_gridTop != null) + if (_panelTop != null) { - _gridTop.MouseLeftButtonDown -= GridTop_OnMouseLeftButtonDown; + _panelTop.MouseLeftButtonDown -= PanelTopOnMouseLeftButtonDown; } if (_imageViewer != null) @@ -94,12 +94,12 @@ namespace HandyControl.Controls base.OnApplyTemplate(); - _gridTop = GetTemplateChild(ElementGridTop) as Grid; + _panelTop = GetTemplateChild(ElementPanelTop) as Panel; _imageViewer = GetTemplateChild(ElementImageViewer) as ImageViewer; - if (_gridTop != null) + if (_panelTop != null) { - _gridTop.MouseLeftButtonDown += GridTop_OnMouseLeftButtonDown; + _panelTop.MouseLeftButtonDown += PanelTopOnMouseLeftButtonDown; } if (_imageViewer != null) @@ -110,7 +110,7 @@ namespace HandyControl.Controls private void ButtonClose_OnClick(object sender, RoutedEventArgs e) => Close(); - private void GridTop_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + private void PanelTopOnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { diff --git a/HandyControl/Controls/Window/MessageBox.cs b/HandyControl/Controls/Window/MessageBox.cs index 36007596..67342fd7 100644 --- a/HandyControl/Controls/Window/MessageBox.cs +++ b/HandyControl/Controls/Window/MessageBox.cs @@ -1,14 +1,12 @@ using System; using System.ComponentModel; +using System.Text; using System.Windows; -using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; -using System.Windows.Shapes; using HandyControl.Data; using HandyControl.Interactivity; using HandyControl.Tools; -using HandyControl.Tools.Extension; namespace HandyControl.Controls { @@ -17,14 +15,6 @@ namespace HandyControl.Controls /// public sealed class MessageBox : Window { - #region Constants - - private const string ElementImage = "PART_Image"; - - private const string ElementMessage = "PART_Message"; - - #endregion Constants - private MessageBoxResult _messageBoxResult = MessageBoxResult.Cancel; private bool _showOk; @@ -35,13 +25,41 @@ namespace HandyControl.Controls private bool _showNo; - private string _message; + public static readonly DependencyProperty MessageProperty = DependencyProperty.Register( + "Message", typeof(string), typeof(MessageBox), new PropertyMetadata(default(string))); - private Geometry _image; + public string Message + { + get => (string) GetValue(MessageProperty); + set => SetValue(MessageProperty, value); + } - private Brush _imageBrush; + public static readonly DependencyProperty ImageProperty = DependencyProperty.Register( + "Image", typeof(Geometry), typeof(MessageBox), new PropertyMetadata(default(Geometry))); - private bool _showImage; + public Geometry Image + { + get => (Geometry) GetValue(ImageProperty); + set => SetValue(ImageProperty, value); + } + + public static readonly DependencyProperty ImageBrushProperty = DependencyProperty.Register( + "ImageBrush", typeof(Brush), typeof(MessageBox), new PropertyMetadata(default(Brush))); + + public Brush ImageBrush + { + get => (Brush) GetValue(ImageBrushProperty); + set => SetValue(ImageBrushProperty, value); + } + + public static readonly DependencyProperty ShowImageProperty = DependencyProperty.Register( + "ShowImage", typeof(bool), typeof(MessageBox), new PropertyMetadata(ValueBoxes.FalseBox)); + + public bool ShowImage + { + get => (bool) GetValue(ShowImageProperty); + set => SetValue(ShowImageProperty, value); + } private MessageBox() { @@ -67,20 +85,48 @@ namespace HandyControl.Controls }, (s, e) => e.CanExecute = _showNo)); } - protected override void OnSourceInitialized(EventArgs e) + protected override void OnPreviewKeyDown(KeyEventArgs e) { - base.OnSourceInitialized(e); + base.OnPreviewKeyDown(e); - if (LogicalTreeHelper.FindLogicalNode(this, ElementMessage) is TextBlock message) message.Text = _message; - - if (_showImage) + if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.C) { - if (LogicalTreeHelper.FindLogicalNode(this, ElementImage) is Path image) + var builder = new StringBuilder(); + var line = new string('-', 27); + builder.Append(line); + builder.Append(Environment.NewLine); + builder.Append(Title); + builder.Append(Environment.NewLine); + builder.Append(line); + builder.Append(Environment.NewLine); + builder.Append(Message); + builder.Append(Environment.NewLine); + builder.Append(line); + builder.Append(Environment.NewLine); + if (_showOk) { - image.Data = _image; - image.Fill = _imageBrush; - image.Show(); + builder.Append(Properties.Langs.Lang.Confirm); + builder.Append(" "); } + if (_showYes) + { + builder.Append(Properties.Langs.Lang.Yes); + builder.Append(" "); + } + if (_showNo) + { + builder.Append(Properties.Langs.Lang.No); + builder.Append(" "); + } + if (_showCancel) + { + builder.Append(Properties.Langs.Lang.Cancel); + builder.Append(" "); + } + builder.Append(Environment.NewLine); + builder.Append(line); + builder.Append(Environment.NewLine); + Clipboard.SetText(builder.ToString()); } } @@ -96,9 +142,9 @@ namespace HandyControl.Controls { messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK); SetButtonStatus(messageBox, MessageBoxButton.OK); - messageBox._showImage = true; - messageBox._image = ResourceHelper.GetResource(ResourceToken.SuccessGeometry); - messageBox._imageBrush = ResourceHelper.GetResource(ResourceToken.SuccessBrush); + messageBox.ShowImage = true; + messageBox.Image = ResourceHelper.GetResource(ResourceToken.SuccessGeometry); + messageBox.ImageBrush = ResourceHelper.GetResource(ResourceToken.SuccessBrush); messageBox.ShowDialog(); }); @@ -174,9 +220,9 @@ namespace HandyControl.Controls { messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK); SetButtonStatus(messageBox, MessageBoxButton.OK); - messageBox._showImage = true; - messageBox._image = ResourceHelper.GetResource(ResourceToken.FatalGeometry); - messageBox._imageBrush = ResourceHelper.GetResource(ResourceToken.PrimaryTextBrush); + messageBox.ShowImage = true; + messageBox.Image = ResourceHelper.GetResource(ResourceToken.FatalGeometry); + messageBox.ImageBrush = ResourceHelper.GetResource(ResourceToken.PrimaryTextBrush); messageBox.ShowDialog(); }); @@ -217,9 +263,9 @@ namespace HandyControl.Controls if (!string.IsNullOrEmpty(info.IconKey)) { - messageBox._showImage = true; - messageBox._image = ResourceHelper.GetResource(info.IconKey); - messageBox._imageBrush = ResourceHelper.GetResource(info.IconBrushKey); + messageBox.ShowImage = true; + messageBox.Image = ResourceHelper.GetResource(info.IconKey); + messageBox.ImageBrush = ResourceHelper.GetResource(info.IconBrushKey); } messageBox.Style = info.Style; @@ -293,9 +339,9 @@ namespace HandyControl.Controls return new MessageBox { - _message = messageBoxText, + Message = messageBoxText, Owner = ownerWindow, - WindowStartupLocation = ownerIsNull ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner, + WindowStartupLocation = WindowStartupLocation.CenterScreen, ShowTitle = true, Title = caption ?? string.Empty, Topmost = ownerIsNull, @@ -352,9 +398,9 @@ namespace HandyControl.Controls } if (string.IsNullOrEmpty(iconKey)) return; - messageBox._showImage = true; - messageBox._image = ResourceHelper.GetResource(iconKey); - messageBox._imageBrush = ResourceHelper.GetResource(iconBrushKey); + messageBox.ShowImage = true; + messageBox.Image = ResourceHelper.GetResource(iconKey); + messageBox.ImageBrush = ResourceHelper.GetResource(iconBrushKey); } private static bool IsValidMessageBoxButton(MessageBoxButton value) diff --git a/HandyControl/Controls/Window/Window.cs b/HandyControl/Controls/Window/Window.cs index ee8d9fc1..be713cfb 100644 --- a/HandyControl/Controls/Window/Window.cs +++ b/HandyControl/Controls/Window/Window.cs @@ -1,11 +1,9 @@ using System; using System.Windows; -using System.Windows.Controls; using System.Windows.Data; using System.Windows.Input; using System.Windows.Media; using HandyControl.Data; -using HandyControl.Tools; using HandyControl.Tools.Extension; #if netle40 using Microsoft.Windows.Shell; @@ -81,14 +79,14 @@ namespace HandyControl.Controls private bool _isFullScreen; + private Thickness _actualBorderThickness; + private UIElement _nonClientArea; private bool _showNonClientArea = true; private double _tempNonClientAreaHeight; - private Thickness _tempThickness; - private WindowState _tempWindowState; private WindowStyle _tempWindowStyle; @@ -106,31 +104,7 @@ namespace HandyControl.Controls new Binding(NonClientAreaHeightProperty.Name) {Source = this}); WindowChrome.SetWindowChrome(this, chrome); - Loaded += delegate - { - _tempThickness = BorderThickness; - if (WindowState == WindowState.Maximized) - { - BorderThickness = new Thickness(); - } - - CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, - (s, e) => WindowState = WindowState.Minimized)); - CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, - (s, e) => WindowState = WindowState.Maximized)); - CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, - (s, e) => WindowState = WindowState.Normal)); - CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (s, e) => Close())); - CommandBindings.Add(new CommandBinding(SystemCommands.ShowSystemMenuCommand, ShowSystemMenu)); - - _tempNonClientAreaHeight = NonClientAreaHeight; - _tempWindowState = WindowState; - _tempWindowStyle = WindowStyle; - _tempResizeMode = ResizeMode; - - SwitchIsFullScreen(_isFullScreen); - SwitchShowNonClientArea(_showNonClientArea); - }; + Loaded += (s, e) => OnLoaded(e); } public Brush CloseButtonBackground @@ -317,15 +291,34 @@ namespace HandyControl.Controls } else if (WindowState == WindowState.Normal) { - BorderThickness = _tempThickness; + BorderThickness = _actualBorderThickness; } } - public override void OnApplyTemplate() + protected void OnLoaded(RoutedEventArgs args) { - base.OnApplyTemplate(); + _actualBorderThickness = BorderThickness; + if (WindowState == WindowState.Maximized) + { + BorderThickness = new Thickness(); + } - _nonClientArea = GetTemplateChild(ElementNonClientArea) as UIElement; + CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, + (s, e) => WindowState = WindowState.Minimized)); + CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, + (s, e) => WindowState = WindowState.Maximized)); + CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, + (s, e) => WindowState = WindowState.Normal)); + CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (s, e) => Close())); + CommandBindings.Add(new CommandBinding(SystemCommands.ShowSystemMenuCommand, ShowSystemMenu)); + + _tempNonClientAreaHeight = NonClientAreaHeight; + _tempWindowState = WindowState; + _tempWindowStyle = WindowStyle; + _tempResizeMode = ResizeMode; + + SwitchIsFullScreen(_isFullScreen); + SwitchShowNonClientArea(_showNonClientArea); if (SizeToContent != SizeToContent.WidthAndHeight) return; @@ -334,11 +327,18 @@ namespace HandyControl.Controls Dispatcher.BeginInvoke(new Action(() => { SizeToContent = SizeToContent.WidthAndHeight; })); } + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + _nonClientArea = GetTemplateChild(ElementNonClientArea) as UIElement; + } + private void ShowSystemMenu(object sender, ExecutedRoutedEventArgs e) { var point = WindowState == WindowState.Maximized - ? new Point(0, 28) - : new Point(Left, Top + 28); + ? new Point(0, NonClientAreaHeight) + : new Point(Left, Top + NonClientAreaHeight); SystemCommands.ShowSystemMenu(this, point); } @@ -348,28 +348,5 @@ namespace HandyControl.Controls if (SizeToContent == SizeToContent.WidthAndHeight) InvalidateMeasure(); } - - /// - /// 获取自定义窗口 - /// - /// - public static Window GetCustomWindow(FrameworkElement content) - { - var window = new Window - { - Style = ResourceHelper.GetResource--> - \ No newline at end of file diff --git a/HandyControl/Themes/Styles/MessageBox.xaml b/HandyControl/Themes/Styles/MessageBox.xaml index f2f30ce0..9ced6f85 100644 --- a/HandyControl/Themes/Styles/MessageBox.xaml +++ b/HandyControl/Themes/Styles/MessageBox.xaml @@ -17,30 +17,106 @@ - + - - - - - - - - - - - - - - -