diff --git a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamTemplateSelector.cs b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamTemplateSelector.cs index 747c8e569..15f85ce26 100644 --- a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamTemplateSelector.cs +++ b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamTemplateSelector.cs @@ -1,6 +1,8 @@ +using bts.collections; using bts.spark; using mbts.spark; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reactive.Linq; @@ -9,7 +11,14 @@ using System.Windows; using System.Windows.Controls; namespace mbts.ui.spark { + static class AlgoParamTemplateKeys { + public const string Price = nameof(Price); + } + + /// TODO: remove this class and just use a . class AlgoParamTemplateSelector : DataTemplateSelector { + KeyedCollection _keyed_templates = new KeyedCollection(tsk => tsk.Key); + public DataTemplate BoolTemplate { get; set; } public DataTemplate NullableBoolTemplate { get; set; } public DataTemplate IntTemplate { get; set; } @@ -25,7 +34,14 @@ namespace mbts.ui.spark { public DataTemplate ExecutionStrategyTemplate { get; set; } public DataTemplate TimestampTemplate { get; set; } + /// is needed for the 'price' param. Price was formerly edited in a separate control, however now it is just another param row. + /// Before this, the generic type argument in the implementation was enough to determine the template. + /// Since 'price' is just a double, further specification was needed to associate it with a 'PriceEntryControl' template. + public IList KeyedTemplates => _keyed_templates; + public override DataTemplate SelectTemplate(object item, DependencyObject container) { + if (item is ITemplateSelectorKey tsk && tsk.key is string template_key && _keyed_templates.TryGetValue(template_key, out var tkv)) + return tkv.Value; IAlgoParamVM pvm = item as IAlgoParamVM ?? (item as AlgoParamRowVM)?.param; if (pvm != null) { if (pvm is IAlgoParamVM) return DoubleTemplate; @@ -55,4 +71,4 @@ namespace mbts.ui.spark { return null; } } -} \ No newline at end of file +}