| 1 | private QuantityUpDown qudSelector; |
| 2 | private TifSelector tifSelector; |
| 3 | private AtmStrategy.AtmStrategySelector atmStrategySelector; |
| 4 | |
| 5 | private 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 | |
| 51 | private 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 |
| 60 | public override void Cleanup() |
| 61 | { |
| 62 | // Clean up our resources |
| 63 | base.Cleanup(); |
| 64 | } |