public override DataTemplate SelectTemplate(object item, DependencyObject container) { DebugHelper.AssertUIThread(); DataTemplate result = null; if (this.pluginService != null) { if (this.readOnly.GetValueOrDefault(false)) { if (item is KeyValuePair <string, object> ) { KeyValuePair <string, object> keyValue = (KeyValuePair <string, object>)item; result = this.pluginService.GetReadOnlyFileMetadataDataTemplate(keyValue.Value.GetType(), keyValue.Key); } } else { MetadataKeyValuePair keyValue = item as MetadataKeyValuePair; if (keyValue != null) { result = this.pluginService.GetWritableFileMetadataDataTemplate(keyValue.Value.GetType(), keyValue.Key); } else if (item is KeyValuePair <string, object> ) { KeyValuePair <string, object> keyValue2 = (KeyValuePair <string, object>)item; result = this.pluginService.GetReadOnlyFileMetadataDataTemplate(keyValue2.Value.GetType(), keyValue2.Key); } } } return(result); }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { DebugHelper.AssertUIThread(); DataTemplate result = null; if (this.pluginService != null) { string key = null; Type valueType = null; Guid dataTypeId = Guid.Empty; Guid semanticId = Guid.Empty; MetadataKeyValuePair kv = item as MetadataKeyValuePair; if (kv != null) { Debug.Assert(kv.Value != null); key = kv.Key; valueType = kv.Value.GetType(); kv.GetStreamIds(out dataTypeId, out semanticId); } else if (item is KeyValuePair <string, object> ) { KeyValuePair <string, object> kv2 = (KeyValuePair <string, object>)item; Debug.Assert(kv2.Value != null); key = kv2.Key; valueType = kv2.Value.GetType(); // In order to keep the standard Metadata collection as a normal IDictionary (and thus have normal // KeyValuePair) and not have to copy over read-only metadata into a separate collection proxy, // set the stream as the DataContext of the ListView parent, and just look it up. DependencyObject obj = container; while (true) { obj = VisualTreeHelper.GetParent(obj); if (obj == null) { break; } FrameworkElement element = obj as FrameworkElement; if (element != null) { KStudioEventStream stream = element.Tag as KStudioEventStream; if (stream != null) { dataTypeId = stream.DataTypeId; semanticId = stream.SemanticId; break; } } } } if (this.readOnly.GetValueOrDefault(false)) { result = this.pluginService.GetReadOnlyStreamMetadataDataTemplate(valueType, key, dataTypeId, semanticId); } else { result = this.pluginService.GetWritableStreamMetadataDataTemplate(valueType, key, dataTypeId, semanticId); } } return(result); }