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 11459e1bc..5b7aa2be7 100644 --- a/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamTemplateSelector.cs +++ b/src/client/spark/Modules/Trading/AlgoStudio/View/AlgoEditorGridView/AlgoParamTemplateSelector.cs @@ -21,7 +21,7 @@ namespace mbts.ui.spark { class AlgoParamTemplateSelector : DataTemplateSelector { public static readonly Type generic_algo_param_itype = typeof(IAlgoParamVM<>); - KeyedCollection _keyed_templates = new KeyedCollection(tsk => tsk.Key); + KeyedCollection _keyed_templates = new KeyedCollection(tsk => tsk.Key.ToString()); public DataTemplate BoolTemplate { get; set; } public DataTemplate NullableBoolTemplate { get; set; } diff --git a/src/client/spark/view/Utility/KeyedTemplateSelector.cs b/src/client/spark/view/Utility/KeyedTemplateSelector.cs index fad5918bd..66e844ae0 100644 --- a/src/client/spark/view/Utility/KeyedTemplateSelector.cs +++ b/src/client/spark/view/Utility/KeyedTemplateSelector.cs @@ -11,21 +11,26 @@ namespace mbts.ui { [ContentProperty(nameof(Map))] class KeyedTemplateSelector : DataTemplateSelector { - KeyedCollection _c = new KeyedCollection(kv => kv.Key); + KeyedCollection _c = new KeyedCollection(kv => kv.Key); public IList Map => _c; public DataTemplate Default { get; set; } + public bool TryMatchType { get; set; } public override DataTemplate SelectTemplate(object item, DependencyObject container) { - if (item is ITemplateSelectorKey k && k.key != null && _c.TryGetValue(k.key, out TemplateSelectorKeyValue result)) + if (item != null && + ((item is ITemplateSelectorKey k && k.key != null && _c.TryGetValue(k.key, out var result)) || + (TryMatchType && _c.TryGetValue(item.GetType(), out result)))) { + // return result.Value; - else return Default; + } + return Default; } } [ContentProperty(nameof(Value))] class TemplateSelectorKeyValue { - public string Key { get; set; } + public object Key { get; set; } public DataTemplate Value { get; set; } } } \ No newline at end of file