123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- /*-------------------------------------------------------------------------
- * 功能描述:DockableWindow
- * 作者:xulisong
- * 创建时间: 2019/5/31 17:13:16
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using Autodesk.Revit.UI;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- namespace FWindSoft.Revit
- {
- public class DockableWindow : Page, IDockablePaneProvider
- {
- public DockableWindow()
- {
- Background = Brushes.White;
- }
- #region 属性相关,注册时使用
- /// <summary>
- /// 关联PaneId
- /// </summary>
- public DockablePaneId PaneId { get; private set; }
- /// <summary>
- /// 关联UIControlledApplication
- /// </summary>
- public UIControlledApplication UIControlledApplication { get; private set; }
- /// <summary>
- /// 关联UIApplication
- /// </summary>
- public UIApplication UIApplication { get; private set; }
- #endregion
- public virtual void SetupDockablePane(DockablePaneProviderData data)
- {
- data.FrameworkElement = this as FrameworkElement;
- data.InitialState = new DockablePaneState();
- data.InitialState.DockPosition = DockPosition.Right;
- if (data.InitialState.DockPosition == DockPosition.Floating)
- {
- data.InitialState.SetFloatingRectangle(new Autodesk.Revit.DB.Rectangle(100, 100, 100, 100));
- }
- }
- /// <summary>
- /// 注册窗体到app
- /// </summary>
- /// <param name="application"></param>
- /// <param name="mainGuid"></param>
- public DockableWindow RegisterDockableWindow(UIControlledApplication application, DockablePaneId mainGuid)
- {
- string title = string.IsNullOrWhiteSpace(this.Title) ? this.GetType().ToString() : this.Title;
- UIControlledApplication = application;
- PaneId = mainGuid;
- return RevitCustomDockablePanels.RegisterDockablePane(application, PaneId, title, this);
- }
- public DockableWindow RegisterDockableWindow(UIApplication application, DockablePaneId mainGuid)
- {
- string title = string.IsNullOrWhiteSpace(this.Title) ? this.GetType().ToString() : this.Title;
- UIApplication = application;
- PaneId = mainGuid;
- return RevitCustomDockablePanels.RegisterDockablePane(application, PaneId, title, this);
- }
- public new void Show()
- {
- try
- {
- DockablePane dockPane = null;
- if (UIControlledApplication != null)
- {
- dockPane = RevitCustomDockablePanels.GetDockablePane(UIControlledApplication, PaneId);
- }
- else if (UIApplication != null)
- {
- dockPane = RevitCustomDockablePanels.GetDockablePane(UIControlledApplication, PaneId);
- }
- if (dockPane != null)
- {
- dockPane.Show();
- }
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- public new void Close()
- {
- try
- {
- DockablePane dockPane = null;
- if (UIControlledApplication != null)
- {
- dockPane = RevitCustomDockablePanels.GetDockablePane(UIControlledApplication, PaneId);
- }
- else if (UIApplication != null)
- {
- dockPane = RevitCustomDockablePanels.GetDockablePane(UIControlledApplication, PaneId);
- }
- if (dockPane != null)
- {
- dockPane.Hide();
- }
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- }
- }
|