added DataTypeTemplateSelector
This commit is contained in:
1 parent
727f39b6a6
commit
a36f9278d5
1 file changed
+19
@@ -0,0 +1,19 @@
|
||||
using bts.collections;
|
||||
using System.Collections;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace mbts.ui {
|
||||
[ContentProperty(nameof(Map))]
|
||||
class DataTypeTemplateSelector : DataTemplateSelector {
|
||||
KeyedCollection<DataTemplate, object> _c = new KeyedCollection<DataTemplate, object>(t => t.DataTemplateKey);
|
||||
|
||||
public IList Map => _c;
|
||||
|
||||
public DataTemplate Default { get; set; }
|
||||
|
||||
public override DataTemplate SelectTemplate(object item, DependencyObject container) =>
|
||||
item != null && _c.TryGetValue(new DataTemplateKey(item.GetType()), out var result) ? result : Default;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user