KeyedTemplateSelector 'TryMatchType' fallback behavior
This commit is contained in:
1 parent
7bdd60e744
commit
d507ea6d16
2 files changed
+10
-5
No files matched your search
+1
-1
@@ -21,7 +21,7 @@ namespace mbts.ui.spark {
|
||||
class AlgoParamTemplateSelector : DataTemplateSelector {
|
||||
public static readonly Type generic_algo_param_itype = typeof(IAlgoParamVM<>);
|
||||
|
||||
KeyedCollection<TemplateSelectorKeyValue, string> _keyed_templates = new KeyedCollection<TemplateSelectorKeyValue, string>(tsk => tsk.Key);
|
||||
KeyedCollection<TemplateSelectorKeyValue, string> _keyed_templates = new KeyedCollection<TemplateSelectorKeyValue, string>(tsk => tsk.Key.ToString());
|
||||
|
||||
public DataTemplate BoolTemplate { get; set; }
|
||||
public DataTemplate NullableBoolTemplate { get; set; }
|
||||
|
||||
@@ -11,21 +11,26 @@ namespace mbts.ui {
|
||||
|
||||
[ContentProperty(nameof(Map))]
|
||||
class KeyedTemplateSelector : DataTemplateSelector {
|
||||
KeyedCollection<TemplateSelectorKeyValue, string> _c = new KeyedCollection<TemplateSelectorKeyValue, string>(kv => kv.Key);
|
||||
KeyedCollection<TemplateSelectorKeyValue, object> _c = new KeyedCollection<TemplateSelectorKeyValue, object>(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; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user