Adding properties to dockable pane

Adding properties to dockable pane

Kevin.Bell
Advisor Advisor
1,886 Views
6 Replies
Message 1 of 7

Adding properties to dockable pane

Kevin.Bell
Advisor
Advisor

Hi,

 

I've a routine I created for Revit which opens certain views - this uses Win Forms a modeless dialog.

 

I've decided to update this to a dockable pane, and so I'm in the process of moving it to WPF (and learning WPF!).

 

Originally, when using a Form, I passed several variables to it, I did this by creating some properties in the Form class, i.e.

 

        public List<ElementId> getAllSheets_IDs
        {
            get;
            set;
        }

When the External Command ran I created the form with 

 

var myForm = new Form1();

 

And I could access the property with myForm.getAllSheets_IDs - this worked well.

 

Now moving to WPF, I have to register the dockable pane in the App : IExternalApplication class which I understand runs when Revit loads (as the docable form needs to be registered in a zero doc state).

 

This means that the instance of my pane is created in App : IExternalApplication class and I cannot access it from the class Command : IExternalCommand hence I cannot access any properties of it.

 

Is there a way I can pass data to the pane?

 

I hope my explanation above make sense, I'm a bit of a noob at this!

 

Cheers.

 

 

0 Likes
1,887 Views
6 Replies
Replies (6)
Message 2 of 7

RPTHOMAS108
Mentor
Mentor

1) Create XAML page with code behind that implements IDockablePaneProvider

2) Create a new item of (1) non-static and assign it to a public static variable in your class that registers the pane (IExternalApplication) 

3) Pass the non-static variable as an argument to Application.RegisterDockablePane

4) Access the static variable of your pane to update it from IExternalCommand class

 

This is the order I found works for me. However it would seem logical to pass the static variable directly into Application.RegisterDockablePane. Probably I tried this and perhaps it didn't work but I don't see why it wouldn't.

 

 

 

 

0 Likes
Message 3 of 7

Kevin.Bell
Advisor
Advisor

Hi RPTHOMAS108, thanks for your reply.

 

I'm trying to follow what you've said:

 

1) Create XAML page with code behind that implements IDockablePaneProvider

OK, I've created a WPF form, which is XAML, the .XAML.CS code behnd it impliments IDockablePaneProvider with:

   public partial class NewBrowserPane : UserControl, IDockablePaneProvider
    {
        public void SetupDockablePane(DockablePaneProviderData data)
        {
            data.FrameworkElement = this as FrameworkElement;
            data.InitialState.DockPosition = DockPosition.Tabbed;
            data.InitialState.TabBehind = Autodesk.Revit.UI.DockablePanes.BuiltInDockablePanes.ElementView;
        }

        public NewBrowserPane()
        {
            InitializeComponent();
        }
    }

 


2) Create a new item of (1) non-static and assign it to a public static variable in your class that registers the pane (IExternalApplication) 

OK, I believe I've done this in IExternalApplication with, I've created a public static variable - myPane, when I create the panelId I then assign it to myPane

    class App : IExternalApplication
    {
        public static DockablePaneId myPane
        {
            get;
            set;
        }        

        public Result OnStartup(UIControlledApplication a)
        {
            //Register dockable pane
            NewBrowserPane page1 = new NewBrowserPane();
            DockablePaneId paneId = new DockablePaneId(new Guid("9d7ed357-534f-4d87-afc4-8e784e3b119e"));

            myPane = paneId;

            a.RegisterDockablePane(paneId, "Test", (IDockablePaneProvider)page1);

            return Result.Succeeded;
        }
}

 


3) Pass the non-static variable as an argument to Application.RegisterDockablePane

I'm stuck on this bit, I believe I should change 

 

a.RegisterDockablePane(paneId, "New Browser", (IDockablePaneProvider)page1);

 

to 

 

a.RegisterDockablePane(paneId, "New Browser", (IDockablePaneProvider)page1, myPane)

 

But I can't access the definition of RegisterDockablePane to add the myPane arguement.

 

Am I following your instructions correctly?

 

Cheers,

 

 

 

0 Likes
Message 4 of 7

RPTHOMAS108
Mentor
Mentor

There are a couple of things wrong with your implementation as far as I can see:

 

  1. You should be using a WPF Page not a UserControl for the pane content
  2. DockablePaneId should be provided as a class level static variable
  3. Should try casting Pane to IDockablePaneProvider when passing into RegisterDockablePane

For comparison I've created a project with a basic implementation for dockable pane this has a separate IExternalCommand  (External Tools dropdown on Add-ins tab) which will update the pane with the time. Dockable panes would usually be used in conjunction with idling event to update them and ExternalEvent to take instructions from them.

 

 

Message 5 of 7

Kevin.Bell
Advisor
Advisor

Thanks for your response, I'll review your code.

 

One point about userControl vs WPF Page, when I click 'Add' and 'New Item' in Visual Studio I only get the option to add a userControl, WPF Page is not listed.

 

Though I see on the code that you sent, when I click Add New Item, WPF Page is listed. It appears that something in my solution is preventing Visual Studio from giving the option of adding a WPF Page?

0 Likes
Message 6 of 7

RPTHOMAS108
Mentor
Mentor

Sounds like you started with the wrong template.

 

If you pick a .Net Framework class library it assumes you want to use Window.Forms. Now it is slightly more complicated with the addition of .Net Core and .Net Standard.

 

Historically I always created a WPF class library by starting a WPF Application project type and switching the Output type to Class Library then deleting  the files associated with an application i.e. App.xaml and App.config.

 

Once you have the WPF project started in such a way you then save it as a template.

Message 7 of 7

Kevin.Bell
Advisor
Advisor

Oh, OK.

 

I use the Revit addin template by The Building Coder: https://thebuildingcoder.typepad.com/blog/2018/09/revit-2019-visual-studio-net-add-in-wizards.html

 

Thats obvioudly set up for Windows Forms as you say... I'll have to create a new one.

 

Cheers.

0 Likes