Mercurial > silverbladetech
comparison SilverlightGlimpse/FloatableWindow/FloatableWindow.cs @ 69:a0bcd783e612
Latest work
author | Steven Hollidge <stevenhollidge@hotmail.com> |
---|---|
date | Mon, 23 Apr 2012 11:06:10 +0100 |
parents | 810116cd6b8e |
children |
comparison
equal
deleted
inserted
replaced
68:81337ebf885a | 69:a0bcd783e612 |
---|---|
23 [TemplatePart(Name = PART_CloseButton, Type = typeof(ButtonBase))] | 23 [TemplatePart(Name = PART_CloseButton, Type = typeof(ButtonBase))] |
24 [TemplatePart(Name = PART_ContentPresenter, Type = typeof(FrameworkElement))] | 24 [TemplatePart(Name = PART_ContentPresenter, Type = typeof(FrameworkElement))] |
25 [TemplatePart(Name = PART_ContentRoot, Type = typeof(FrameworkElement))] | 25 [TemplatePart(Name = PART_ContentRoot, Type = typeof(FrameworkElement))] |
26 [TemplatePart(Name = PART_Overlay, Type = typeof(Panel))] | 26 [TemplatePart(Name = PART_Overlay, Type = typeof(Panel))] |
27 [TemplatePart(Name = PART_Root, Type = typeof(FrameworkElement))] | 27 [TemplatePart(Name = PART_Root, Type = typeof(FrameworkElement))] |
28 [TemplatePart(Name = PART_Resizer, Type = typeof(FrameworkElement))] | |
29 [TemplateVisualState(Name = VSMSTATE_StateClosed, GroupName = VSMGROUP_Window)] | 28 [TemplateVisualState(Name = VSMSTATE_StateClosed, GroupName = VSMGROUP_Window)] |
30 [TemplateVisualState(Name = VSMSTATE_StateOpen, GroupName = VSMGROUP_Window)] | 29 [TemplateVisualState(Name = VSMSTATE_StateOpen, GroupName = VSMGROUP_Window)] |
31 public class FloatableWindow : ContentControl | 30 public class FloatableWindow : ContentControl |
32 { | 31 { |
33 #region Static Fields and Constants | 32 #region Static Fields and Constants |
34 | 33 |
35 /// <summary> | 34 /// <summary> |
36 /// The name of the Chrome template part. | 35 /// The name of the Chrome template part. |
37 /// </summary> | 36 /// </summary> |
38 private const string PART_Chrome = "Chrome"; | 37 private const string PART_Chrome = "Chrome"; |
39 | |
40 /// <summary> | |
41 /// The name of the Resizer template part. | |
42 /// </summary> | |
43 private const string PART_Resizer = "Resizer"; | |
44 | 38 |
45 /// <summary> | 39 /// <summary> |
46 /// The name of the CloseButton template part. | 40 /// The name of the CloseButton template part. |
47 /// </summary> | 41 /// </summary> |
48 private const string PART_CloseButton = "CloseButton"; | 42 private const string PART_CloseButton = "CloseButton"; |
412 /// </summary> | 406 /// </summary> |
413 public FloatableWindow() | 407 public FloatableWindow() |
414 { | 408 { |
415 this.DefaultStyleKey = typeof(FloatableWindow); | 409 this.DefaultStyleKey = typeof(FloatableWindow); |
416 this.InteractionState = WindowInteractionState.NotResponding; | 410 this.InteractionState = WindowInteractionState.NotResponding; |
417 this.ResizeMode = ResizeMode.CanResize; | |
418 } | 411 } |
419 | 412 |
420 #endregion Constructors | 413 #endregion Constructors |
421 | 414 |
422 #region Events | 415 #region Events |
435 | 428 |
436 #endregion Events | 429 #endregion Events |
437 | 430 |
438 #region Properties | 431 #region Properties |
439 | 432 |
433 private Panel _parentLayoutRoot; | |
440 public Panel ParentLayoutRoot | 434 public Panel ParentLayoutRoot |
441 { | 435 { |
442 get; | 436 get { return _parentLayoutRoot; } |
443 set; | 437 set { _parentLayoutRoot = value; } |
444 } | 438 } |
445 | 439 |
446 /// <summary> | 440 /// <summary> |
447 /// Gets the internal accessor for the ContentRoot of the window. | 441 /// Gets the internal accessor for the ContentRoot of the window. |
448 /// </summary> | 442 /// </summary> |
568 /// </summary> | 562 /// </summary> |
569 internal Panel Overlay | 563 internal Panel Overlay |
570 { | 564 { |
571 get; | 565 get; |
572 private set; | 566 private set; |
573 } | |
574 | |
575 public ResizeMode ResizeMode | |
576 { | |
577 get; | |
578 set; | |
579 } | 567 } |
580 | 568 |
581 #endregion Properties | 569 #endregion Properties |
582 | 570 |
583 #region Static Methods | 571 #region Static Methods |
977 } | 965 } |
978 } | 966 } |
979 } | 967 } |
980 | 968 |
981 /// <summary> | 969 /// <summary> |
982 /// Executed when the ContentPresenter size changes. | |
983 /// </summary> | |
984 /// <param name="sender">Content Presenter object.</param> | |
985 /// <param name="e">SizeChanged event args.</param> | |
986 private void ContentPresenter_SizeChanged(object sender, SizeChangedEventArgs e) | |
987 { | |
988 // timheuer: not sure really why this is here? | |
989 //if (this.ContentRoot != null && Application.Current != null && Application.Current.RootVisual != null && _isOpen) | |
990 //{ | |
991 // GeneralTransform gt = this.ContentRoot.TransformToVisual(Application.Current.RootVisual); | |
992 | |
993 // if (gt != null) | |
994 // { | |
995 // Point p = gt.Transform(new Point(0, 0)); | |
996 | |
997 // double x = this._windowPosition.X - p.X; | |
998 // double y = this._windowPosition.Y - p.Y; | |
999 // UpdateContentRootTransform(x, y); | |
1000 // } | |
1001 //} | |
1002 | |
1003 //RectangleGeometry rg = new RectangleGeometry(); | |
1004 //rg.Rect = new Rect(0, 0, this._contentPresenter.ActualWidth, this._contentPresenter.ActualHeight); | |
1005 //this._contentPresenter.Clip = rg; | |
1006 //this.UpdatePosition(); | |
1007 } | |
1008 | |
1009 /// <summary> | |
1010 /// Finds the X coordinate of a point that is defined by a line. | 970 /// Finds the X coordinate of a point that is defined by a line. |
1011 /// </summary> | 971 /// </summary> |
1012 /// <param name="p1">Starting point of the line.</param> | 972 /// <param name="p1">Starting point of the line.</param> |
1013 /// <param name="p2">Ending point of the line.</param> | 973 /// <param name="p2">Ending point of the line.</param> |
1014 /// <param name="y">Y coordinate of the point.</param> | 974 /// <param name="y">Y coordinate of the point.</param> |
1079 { | 1039 { |
1080 this._opened.Completed -= new EventHandler(this.Opening_Completed); | 1040 this._opened.Completed -= new EventHandler(this.Opening_Completed); |
1081 } | 1041 } |
1082 | 1042 |
1083 this._root = GetTemplateChild(PART_Root) as FrameworkElement; | 1043 this._root = GetTemplateChild(PART_Root) as FrameworkElement; |
1084 this._resizer = GetTemplateChild(PART_Resizer) as FrameworkElement; | |
1085 | 1044 |
1086 if (this._root != null) | 1045 if (this._root != null) |
1087 { | 1046 { |
1088 IList groups = VisualStateManager.GetVisualStateGroups(this._root); | 1047 IList groups = VisualStateManager.GetVisualStateGroups(this._root); |
1089 | 1048 |
1116 } | 1075 } |
1117 } | 1076 } |
1118 } | 1077 } |
1119 //TODO: Figure out why I can't wire up the event below in SubscribeToTemplatePartEvents | 1078 //TODO: Figure out why I can't wire up the event below in SubscribeToTemplatePartEvents |
1120 this._root.MouseLeftButtonDown += new MouseButtonEventHandler(this.ContentRoot_MouseLeftButtonDown); | 1079 this._root.MouseLeftButtonDown += new MouseButtonEventHandler(this.ContentRoot_MouseLeftButtonDown); |
1121 | |
1122 if (this.ResizeMode == ResizeMode.CanResize) | |
1123 { | |
1124 this._resizer.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(Resizer_MouseLeftButtonDown); | |
1125 this._resizer.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(Resizer_MouseLeftButtonUp); | |
1126 this._resizer.MouseMove += new System.Windows.Input.MouseEventHandler(Resizer_MouseMove); | |
1127 this._resizer.MouseEnter += new MouseEventHandler(Resizer_MouseEnter); | |
1128 this._resizer.MouseLeave += new MouseEventHandler(Resizer_MouseLeave); | |
1129 } | |
1130 else | |
1131 { | |
1132 this._resizer.Opacity = 0; | |
1133 } | |
1134 } | 1080 } |
1135 | 1081 |
1136 this.ContentRoot = GetTemplateChild(PART_ContentRoot) as FrameworkElement; | 1082 this.ContentRoot = GetTemplateChild(PART_ContentRoot) as FrameworkElement; |
1137 | 1083 |
1138 this._chrome = GetTemplateChild(PART_Chrome) as FrameworkElement; | 1084 this._chrome = GetTemplateChild(PART_Chrome) as FrameworkElement; |
1155 this.UpdateRenderTransform(); | 1101 this.UpdateRenderTransform(); |
1156 this.ChangeVisualState(); | 1102 this.ChangeVisualState(); |
1157 } | 1103 } |
1158 } | 1104 } |
1159 | 1105 |
1160 void Resizer_MouseLeave(object sender, MouseEventArgs e) | |
1161 { | |
1162 if (!this._isMouseCaptured) | |
1163 { | |
1164 this._resizer.Opacity = .25; | |
1165 } | |
1166 } | |
1167 | |
1168 void Resizer_MouseEnter(object sender, MouseEventArgs e) | |
1169 { | |
1170 if (!this._isMouseCaptured) | |
1171 { | |
1172 this._resizer.Opacity = 1; | |
1173 } | |
1174 } | |
1175 | 1106 |
1176 /// <summary> | 1107 /// <summary> |
1177 /// Raises the | 1108 /// Raises the |
1178 /// <see cref="E:System.Windows.Controls.FloatableWindow.Closed" /> event. | 1109 /// <see cref="E:System.Windows.Controls.FloatableWindow.Closed" /> event. |
1179 /// </summary> | 1110 /// </summary> |
1451 this._chrome.MouseLeftButtonDown += new MouseButtonEventHandler(this.Chrome_MouseLeftButtonDown); | 1382 this._chrome.MouseLeftButtonDown += new MouseButtonEventHandler(this.Chrome_MouseLeftButtonDown); |
1452 this._chrome.MouseLeftButtonUp += new MouseButtonEventHandler(this.Chrome_MouseLeftButtonUp); | 1383 this._chrome.MouseLeftButtonUp += new MouseButtonEventHandler(this.Chrome_MouseLeftButtonUp); |
1453 this._chrome.MouseMove += new MouseEventHandler(this.Chrome_MouseMove); | 1384 this._chrome.MouseMove += new MouseEventHandler(this.Chrome_MouseMove); |
1454 } | 1385 } |
1455 | 1386 |
1456 if (this._contentPresenter != null) | |
1457 { | |
1458 this._contentPresenter.SizeChanged += new SizeChangedEventHandler(this.ContentPresenter_SizeChanged); | |
1459 } | |
1460 } | 1387 } |
1461 | 1388 |
1462 /// <summary> | 1389 /// <summary> |
1463 /// Unsubscribe from events when the FloatableWindow is closed. | 1390 /// Unsubscribe from events when the FloatableWindow is closed. |
1464 /// </summary> | 1391 /// </summary> |
1491 if (this._chrome != null) | 1418 if (this._chrome != null) |
1492 { | 1419 { |
1493 this._chrome.MouseLeftButtonDown -= new MouseButtonEventHandler(this.Chrome_MouseLeftButtonDown); | 1420 this._chrome.MouseLeftButtonDown -= new MouseButtonEventHandler(this.Chrome_MouseLeftButtonDown); |
1494 this._chrome.MouseLeftButtonUp -= new MouseButtonEventHandler(this.Chrome_MouseLeftButtonUp); | 1421 this._chrome.MouseLeftButtonUp -= new MouseButtonEventHandler(this.Chrome_MouseLeftButtonUp); |
1495 this._chrome.MouseMove -= new MouseEventHandler(this.Chrome_MouseMove); | 1422 this._chrome.MouseMove -= new MouseEventHandler(this.Chrome_MouseMove); |
1496 } | |
1497 | |
1498 if (this._contentPresenter != null) | |
1499 { | |
1500 this._contentPresenter.SizeChanged -= new SizeChangedEventHandler(this.ContentPresenter_SizeChanged); | |
1501 } | 1423 } |
1502 } | 1424 } |
1503 | 1425 |
1504 /// <summary> | 1426 /// <summary> |
1505 /// Updates the size of the overlay of the window. | 1427 /// Updates the size of the overlay of the window. |