InstrumentSelector
Definition
InstrumentSelector is a UI element users can interact with for selecting instruments. This can be used with instrument linking between windows.
Events and Properties
| Property | Description |
|---|---|
| Cleanup() | Disposes of the InstrumentSelector (Note: calling the NTTabPage base.Cleanup() is sufficient to clean up this control) |
| Instrument | An Instrument representing the selected instrument |
| InstrumentChanged | Event handler for when the instrument changes on the instrument selector |
Examples
This example demonstrates how to use the instrument selector and properly link its behavior to windows linking.
1 private InstrumentSelector instrumentSelector; 2 private DependencyObject LoadXAML() 3 { 4 // Note: pageContent (not demonstrated in this example) is the page content of the XAML 5 6 // Find the Instrument selector 7 instrumentSelector = LogicalTreeHelper.FindLogicalNode(pageContent, "instrumentSelector") as InstrumentSelector; 8 if (instrumentSelector != null) 9 instrumentSelector.InstrumentChanged += OnInstrumentChanged; 10 } 11 12 // This method is fired when our instrument selector changes instruments 13 private void OnInstrumentChanged(object sender, EventArgs e) 14 { 15 Instrument = sender as Cbi.Instrument; 16 } 17 18 // IInstrumentProvider member. Required if you want to use the instrument link mechanism in this Add On window 19 public Cbi.Instrument Instrument 20 { 21 get { return instrument; } 22 set 23 { 24 instrument = value; 25 if (instrumentSelector != null) 26 instrumentSelector.Instrument = value; 27 28 // Send instrument to other windows linked to the same color 29 PropagateInstrumentChange(value); 30 } 31 } 32 33 // NOTE: Don't forget to clean up resources and unsubscribe to events 34 // Called by TabControl when tab is being removed or window is closed 35 public override void Cleanup() 36 { 37 // Clean up our resources 38 if (instrumentSelector != null) 39 { 40 instrumentSelector.InstrumentChanged -= OnInstrumentChanged; 41 } 42 base.Cleanup();
<page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:accountdata="clr-namespace:NinjaTrader.Gui.AccountData;assembly=NinjaTrader.Gui" xmlns:accountperformance="clr-namespace:NinjaTrader.Gui.AccountPerformance;assembly=NinjaTrader.Gui" xmlns:atmstrategy="clr-namespace:NinjaTrader.Gui.NinjaScript.AtmStrategy;assembly=NinjaTrader.Gui" xmlns:tools="clr-namespace:NinjaTrader.Gui.Tools;assembly=NinjaTrader.Gui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <grid> <grid.columndefinitions> <columndefinition width="Auto"></columndefinition> <columndefinition width="*"></columndefinition> </grid.columndefinitions> <tools:instrumentselector grid.column="0" lastusedgroup="MyAddOn" x:name="instrumentSelector"></tools:instrumentselector> </grid> </page>

