DockableWindow.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:DockableWindow
  3. * 作者:xulisong
  4. * 创建时间: 2019/5/31 17:13:16
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using Autodesk.Revit.UI;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Media;
  16. namespace FWindSoft.Revit
  17. {
  18. public class DockableWindow : Page, IDockablePaneProvider
  19. {
  20. public DockableWindow()
  21. {
  22. Background = Brushes.White;
  23. }
  24. #region 属性相关,注册时使用
  25. /// <summary>
  26. /// 关联PaneId
  27. /// </summary>
  28. public DockablePaneId PaneId { get; private set; }
  29. /// <summary>
  30. /// 关联UIControlledApplication
  31. /// </summary>
  32. public UIControlledApplication UIControlledApplication { get; private set; }
  33. /// <summary>
  34. /// 关联UIApplication
  35. /// </summary>
  36. public UIApplication UIApplication { get; private set; }
  37. #endregion
  38. public virtual void SetupDockablePane(DockablePaneProviderData data)
  39. {
  40. data.FrameworkElement = this as FrameworkElement;
  41. data.InitialState = new DockablePaneState();
  42. data.InitialState.DockPosition = DockPosition.Right;
  43. if (data.InitialState.DockPosition == DockPosition.Floating)
  44. {
  45. data.InitialState.SetFloatingRectangle(new Autodesk.Revit.DB.Rectangle(100, 100, 100, 100));
  46. }
  47. }
  48. /// <summary>
  49. /// 注册窗体到app
  50. /// </summary>
  51. /// <param name="application"></param>
  52. /// <param name="mainGuid"></param>
  53. public DockableWindow RegisterDockableWindow(UIControlledApplication application, DockablePaneId mainGuid)
  54. {
  55. string title = string.IsNullOrWhiteSpace(this.Title) ? this.GetType().ToString() : this.Title;
  56. UIControlledApplication = application;
  57. PaneId = mainGuid;
  58. return RevitCustomDockablePanels.RegisterDockablePane(application, PaneId, title, this);
  59. }
  60. public DockableWindow RegisterDockableWindow(UIApplication application, DockablePaneId mainGuid)
  61. {
  62. string title = string.IsNullOrWhiteSpace(this.Title) ? this.GetType().ToString() : this.Title;
  63. UIApplication = application;
  64. PaneId = mainGuid;
  65. return RevitCustomDockablePanels.RegisterDockablePane(application, PaneId, title, this);
  66. }
  67. public new void Show()
  68. {
  69. try
  70. {
  71. DockablePane dockPane = null;
  72. if (UIControlledApplication != null)
  73. {
  74. dockPane = RevitCustomDockablePanels.GetDockablePane(UIControlledApplication, PaneId);
  75. }
  76. else if (UIApplication != null)
  77. {
  78. dockPane = RevitCustomDockablePanels.GetDockablePane(UIControlledApplication, PaneId);
  79. }
  80. if (dockPane != null)
  81. {
  82. dockPane.Show();
  83. }
  84. }
  85. catch (Exception ex)
  86. {
  87. throw;
  88. }
  89. }
  90. public new void Close()
  91. {
  92. try
  93. {
  94. DockablePane dockPane = null;
  95. if (UIControlledApplication != null)
  96. {
  97. dockPane = RevitCustomDockablePanels.GetDockablePane(UIControlledApplication, PaneId);
  98. }
  99. else if (UIApplication != null)
  100. {
  101. dockPane = RevitCustomDockablePanels.GetDockablePane(UIControlledApplication, PaneId);
  102. }
  103. if (dockPane != null)
  104. {
  105. dockPane.Hide();
  106. }
  107. }
  108. catch (Exception ex)
  109. {
  110. throw;
  111. }
  112. }
  113. }
  114. }