public void RegisterDataTemplates(ResourceDictionary dictionary) { foreach (var item in dictionary.Cast<DictionaryEntry>().Where(item => item.Value is DataTemplate)) { var dataTemplate = (DataTemplate)item.Value; _dataTemplates.Add(dataTemplate); if (dataTemplate.DataType != null && dataTemplate.DataType is Type) _templateByType.Add((Type)dataTemplate.DataType, dataTemplate); } }