AutoHideWindowManager.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*************************************************************************************
  2. Extended WPF Toolkit
  3. Copyright (C) 2007-2013 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features, controls, and fast professional support,
  7. pick up the Plus Edition at http://xceed.com/wpf_toolkit
  8. Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
  9. ***********************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Windows.Threading;
  15. using Xceed.Wpf.AvalonDock.Layout;
  16. namespace Xceed.Wpf.AvalonDock.Controls
  17. {
  18. class AutoHideWindowManager
  19. {
  20. DockingManager _manager;
  21. internal AutoHideWindowManager(DockingManager manager)
  22. {
  23. _manager = manager;
  24. SetupCloseTimer();
  25. }
  26. WeakReference _currentAutohiddenAnchor = null;
  27. public void ShowAutoHideWindow(LayoutAnchorControl anchor)
  28. {
  29. if( _currentAutohiddenAnchor.GetValueOrDefault<LayoutAnchorControl>() != anchor )
  30. {
  31. StopCloseTimer();
  32. _currentAutohiddenAnchor = new WeakReference( anchor );
  33. _manager.AutoHideWindow.Show( anchor );
  34. StartCloseTimer();
  35. }
  36. }
  37. public void HideAutoWindow(LayoutAnchorControl anchor = null)
  38. {
  39. if (anchor == null ||
  40. anchor == _currentAutohiddenAnchor.GetValueOrDefault<LayoutAnchorControl>())
  41. {
  42. StopCloseTimer();
  43. }
  44. else
  45. System.Diagnostics.Debug.Assert(false);
  46. }
  47. DispatcherTimer _closeTimer = null;
  48. void SetupCloseTimer()
  49. {
  50. _closeTimer = new DispatcherTimer(DispatcherPriority.Background);
  51. _closeTimer.Interval = TimeSpan.FromMilliseconds(1500);
  52. _closeTimer.Tick += (s, e) =>
  53. {
  54. if (_manager.AutoHideWindow.IsWin32MouseOver ||
  55. ((LayoutAnchorable)_manager.AutoHideWindow.Model).IsActive ||
  56. _manager.AutoHideWindow.IsResizing)
  57. return;
  58. StopCloseTimer();
  59. };
  60. }
  61. void StartCloseTimer()
  62. {
  63. _closeTimer.Start();
  64. }
  65. void StopCloseTimer()
  66. {
  67. _closeTimer.Stop();
  68. _manager.AutoHideWindow.Hide();
  69. _currentAutohiddenAnchor = null;
  70. }
  71. }
  72. }