1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.View
6 using System.ComponentModel;
7 using System.Diagnostics.CodeAnalysis;
10 using System.Windows.Controls;
11 using System.Windows.Input;
12 using System.Windows.Media;
14 //This class is visual representation of ResizeGrip like control, which is used with ExtenstionWindows to allow
15 //resizing. Actual resize logic is handled by ExtensionSurface class
16 [TemplatePart(Name = "PART_ResizeGrip")]
17 class ExtensionWindowResizeGrip : Control
19 public static readonly DependencyProperty IconProperty =
20 DependencyProperty.Register("Icon", typeof(DrawingBrush), typeof(ExtensionWindowResizeGrip));
22 ExtensionWindow parent;
23 ExtensionSurface surface;
26 [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.InitializeReferenceTypeStaticFieldsInline,
27 Justification = "Overriding metadata for dependency properties in static constructor is the way suggested by WPF")]
28 static ExtensionWindowResizeGrip()
30 DefaultStyleKeyProperty.OverrideMetadata(
31 typeof(ExtensionWindowResizeGrip),
32 new FrameworkPropertyMetadata(typeof(ExtensionWindowResizeGrip)));
35 public DrawingBrush Icon
37 get { return (DrawingBrush)GetValue(IconProperty); }
38 set { SetValue(IconProperty, value); }
41 protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
43 base.OnMouseLeftButtonDown(e);
44 if (this.parent.IsResizable)
46 this.Cursor = Cursors.SizeNWSE;
47 this.offset = e.GetPosition(this);
52 protected override void OnMouseMove(MouseEventArgs args)
54 base.OnMouseMove(args);
55 if (args.LeftButton == MouseButtonState.Pressed && this.IsMouseCaptured)
57 Point currentPosition = Mouse.GetPosition(this.parent);
58 currentPosition.Offset(this.offset.X, this.offset.Y);
59 Size newSize = new Size();
60 newSize.Width = Math.Min(Math.Max(this.parent.MinWidth, currentPosition.X), this.parent.MaxWidth);
61 newSize.Height = Math.Min(Math.Max(this.parent.MinHeight, currentPosition.Y), this.parent.MaxHeight);
62 System.Diagnostics.Debug.WriteLine("NewSize = (" + newSize.Width + "," + newSize.Height + ")");
63 this.surface.SetSize(this.parent, newSize);
67 protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
69 base.OnMouseLeftButtonUp(e);
70 Mouse.OverrideCursor = null;
74 protected override void OnVisualParentChanged(DependencyObject oldParent)
76 base.OnVisualParentChanged(oldParent);
77 if (!DesignerProperties.GetIsInDesignMode(this) &&
78 !ExtensionWindow.TryGetParentExtensionWindow(this, out this.parent, out this.surface))
80 Fx.Assert("ExtensionWindowHeader cannot be used outside ExtensionWindow");