IWorkspacePersistence Interface

View as Markdown

IWorkspacePersistence Interface

When creating your NTWindow, be sure to implement the IWorkspacePersistence interface as well for the ability to save and restore your window with NinjaTrader workspaces.

AddOn Classes which derive from NTWindow or implement IWorkspacePersistence CANNOT be a nested type of another class and MUST have a default constructor.

This interface contains two methods and one property which must be hidden by the implementing class:

MethodDescription
Restore()Restores the window from workspaces.
Save()Saves the window to workspaces.
WorkspaceOptionsSets required workspace options.

Examples

1public class MyWindow : NTWindow, IWorkspacePersistence
2{
3 // default constructor
4 public MyWindow()
5 {
6 // Define our NTWindow. If we want to use NT style tabs, we would define that here.
7
8 // WorkspaceOptions property must be set
9 Loaded += (o, e) =>
10 {
11 if (WorkspaceOptions == null)
12 WorkspaceOptions = new WorkspaceOptions("MyWindow-" + Guid.NewGuid().ToString("N"), this);
13 };
14 }
15
16 // IWorkspacePersistence member. Required for restoring window from workspaces
17 public void Restore(XDocument document, XElement element)
18 {
19 if (MainTabControl != null)
20 MainTabControl.RestoreFromXElement(element);
21 }
22
23 // IWorkspacePersistence member. Required for saving window to workspaces
24 public void Save(XDocument document, XElement element)
25 {
26 if (MainTabControl != null)
27 MainTabControl.SaveToXElement(element);
28 }
29
30 // IWorkspacePersistence member
31 public WorkspaceOptions WorkspaceOptions { get; set; }
32}