QuantityUpDown
Definition
QuantityUpDown can be used as a UI element users can interact with for selecting quantity.
Events and Properties
| Property | Description |
|---|---|
| Value | An 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.
private QuantityUpDown qudSelector;private TifSelector tifSelector;private AtmStrategy.AtmStrategySelector atmStrategySelector;private DependencyObject LoadXAML(){// Note: pageContent (not demonstrated in this example) is the page content of the XAML// Find the Quantity Up-Down selectorqudSelector = LogicalTreeHelper.FindLogicalNode(pageContent, "qudSelector") as QuantityUpDown;// Find the TIF selectortifSelector = LogicalTreeHelper.FindLogicalNode(pageContent, "tifSelector") as TifSelector;// Be sure to bind our account selector to our TIF selector to ensure proper functionalitytifSelector.SetBinding(TifSelector.AccountProperty, new Binding { Source = accountSelector,Path = new PropertyPath("SelectedAccount") });// When our TIF selector's selection changestifSelector.SelectionChanged += (o, args) =>{// Change the selected TIF in the ATM strategy tooif (atmStrategySelector.SelectedAtmStrategy != null)atmStrategySelector.SelectedAtmStrategy.TimeInForce = tifSelector.SelectedTif;};// Find ATM Strategy selector and attach event handleratmStrategySelector = LogicalTreeHelper.FindLogicalNode(pageContent, "atmStrategySelector") as AtmStrategy.AtmStrategySelector;atmStrategySelector.Id = Guid.NewGuid().ToString("N");if (atmStrategySelector != null)atmStrategySelector.CustomPropertiesChanged += OnAtmCustomPropertiesChanged;// Be sure to bind our account selector to our ATM strategy selector to ensure proper functionalityatmStrategySelector.SetBinding(AtmStrategy.AtmStrategySelector.AccountProperty,new Binding { Source = accountSelector, Path = new PropertyPath("SelectedAccount") });// When our ATM selector's selection changesatmStrategySelector.SelectionChanged += (o, args) =>{if (atmStrategySelector.SelectedItem == null)return;if (args.AddedItems.Count > 0){// Change the selected TIF in our TIF selector tooAtmStrategy selectedAtmStrategy = args.AddedItems[0] as AtmStrategy;if (selectedAtmStrategy != null)tifSelector.SelectedTif = selectedAtmStrategy.TimeInForce;}};}private void OnAtmCustomPropertiesChanged(object sender, NinjaScript.AtmStrategy.CustomPropertiesChangedEventArgs args){// Adjust our TIF and Quantity selectors to the new ATM strategy valuestifSelector.SelectedTif = args.NewTif;qudSelector.Value = args.NewQuantity;}// NOTE: Don't forget to clean up resources and unsubscribe to events// Called by TabControl when tab is being removed or window is closedpublic override void Cleanup(){// Clean up our resourcesbase.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="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>