QuantityUpDown

View as Markdown

Definition

QuantityUpDown can be used as a UI element users can interact with for selecting quantity.

Events and Properties

PropertyDescription
ValueAn int representing the quantity

Examples

This example demonstrates how to use the quantity up/down selector and properly link its behavior with the ATM strategy and TIF selectors.

1private QuantityUpDown qudSelector;
2private TifSelector tifSelector;
3private AtmStrategy.AtmStrategySelector atmStrategySelector;
4
5private DependencyObject LoadXAML()
6{
7 // Note: pageContent (not demonstrated in this example) is the page content of the XAML
8 // Find the Quantity Up-Down selector
9 qudSelector = LogicalTreeHelper.FindLogicalNode(pageContent, "qudSelector") as QuantityUpDown;
10
11 // Find the TIF selector
12 tifSelector = LogicalTreeHelper.FindLogicalNode(pageContent, "tifSelector") as TifSelector;
13
14 // Be sure to bind our account selector to our TIF selector to ensure proper functionality
15 tifSelector.SetBinding(TifSelector.AccountProperty, new Binding { Source = accountSelector,
16 Path = new PropertyPath("SelectedAccount") });
17
18 // When our TIF selector's selection changes
19 tifSelector.SelectionChanged += (o, args) =>
20 {
21 // Change the selected TIF in the ATM strategy too
22 if (atmStrategySelector.SelectedAtmStrategy != null)
23 atmStrategySelector.SelectedAtmStrategy.TimeInForce = tifSelector.SelectedTif;
24 };
25
26 // Find ATM Strategy selector and attach event handler
27 atmStrategySelector = LogicalTreeHelper.FindLogicalNode(pageContent, "atmStrategySelector") as AtmStrategy.AtmStrategySelector;
28 atmStrategySelector.Id = Guid.NewGuid().ToString("N");
29 if (atmStrategySelector != null)
30 atmStrategySelector.CustomPropertiesChanged += OnAtmCustomPropertiesChanged;
31
32 // Be sure to bind our account selector to our ATM strategy selector to ensure proper functionality
33 atmStrategySelector.SetBinding(AtmStrategy.AtmStrategySelector.AccountProperty,
34 new Binding { Source = accountSelector, Path = new PropertyPath("SelectedAccount") });
35
36 // When our ATM selector's selection changes
37 atmStrategySelector.SelectionChanged += (o, args) =>
38 {
39 if (atmStrategySelector.SelectedItem == null)
40 return;
41 if (args.AddedItems.Count > 0)
42 {
43 // Change the selected TIF in our TIF selector too
44 AtmStrategy selectedAtmStrategy = args.AddedItems[0] as AtmStrategy;
45 if (selectedAtmStrategy != null)
46 tifSelector.SelectedTif = selectedAtmStrategy.TimeInForce;
47 }
48 };
49}
50
51private void OnAtmCustomPropertiesChanged(object sender, NinjaScript.AtmStrategy.CustomPropertiesChangedEventArgs args)
52{
53 // Adjust our TIF and Quantity selectors to the new ATM strategy values
54 tifSelector.SelectedTif = args.NewTif;
55 qudSelector.Value = args.NewQuantity;
56}
57
58// NOTE: Don't forget to clean up resources and unsubscribe to events
59// Called by TabControl when tab is being removed or window is closed
60public override void Cleanup()
61{
62 // Clean up our resources
63 base.Cleanup();
64}
<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="Auto"></columndefinition>
<columndefinition width="*"></columndefinition>
</grid.columndefinitions>
<tools:quantityupdown grid.column="0" value="1" x:name="qudSelector"></tools:quantityupdown>
<tools:tifselector grid.column="1" x:name="tifSelector">
<atmstrategy:atmstrategyselector grid.column="2" linkedquantity="{Binding Value,
ElementName=qudSelector, Mode=OneWay}" x:name="atmStrategySelector"></atmstrategy:atmstrategyselector>
</tools:tifselector></grid>
</page>