public AddMetadata(WritableMetadataProxy metadata) { DebugHelper.AssertUIThread(); if (metadata == null) { throw new ArgumentNullException("metadata"); } this.metadata = metadata; this.key = Strings.Metadata_DefaultNewKey; if (this.metadata.ContainsKey(this.key)) { string format = Strings.Metadata_DefaultNewKey_Format; int i = 2; while (true) { this.key = String.Format(CultureInfo.CurrentCulture, format, i++); if (!this.metadata.ContainsKey(this.key)) { break; } } } selectedValueType = typeof(String); }
public MetadataKeyValuePair(WritableMetadataProxy proxy, string key, object value) { DebugHelper.AssertUIThread(); if (proxy == null) { throw new ArgumentNullException("proxy"); } if (String.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException("key"); } SetValue(value); this.proxy = proxy; this.key = key; }
private void HandleArrayMetadataCommand(object sender, ExecutedRoutedEventArgs e, bool readOnly) { if (e != null) { e.Handled = true; } FrameworkElement element = sender as FrameworkElement; if (element != null) { Window window = Window.GetWindow(element); object[] parameters = e.Parameter as object[]; if ((window != null) && (parameters != null) && (parameters.Length > 1) && (parameters[1] is IList)) { string itemTemplateKey = null; string key = parameters[0] as string; IList list = parameters[1] as IList; object defaultValue = null; WritableMetadataProxy metadata = null; if (!readOnly && parameters.Length > 2) { metadata = parameters[2] as WritableMetadataProxy; } Func <ObservableCollection <ValueHolder>, Array> func = null; if ((key != null) && (list != null)) { Type listType = list.GetType(); if (listType.IsGenericType) { switch (listType.GetGenericArguments()[0].Name) { case "Byte": defaultValue = default(Byte); itemTemplateKey = readOnly ? "NumberMetadataValueDataTemplate" : "ByteMetadataValueDataTemplate"; func = this.Convert <byte>; break; case "Int16": defaultValue = default(Int16); itemTemplateKey = readOnly ? "NumberMetadataValueDataTemplate" : "Int16MetadataValueDataTemplate"; func = this.Convert <Int16>; break; case "UInt16": defaultValue = default(UInt16); itemTemplateKey = readOnly ? "NumberMetadataValueDataTemplate" : "UInt16MetadataValueDataTemplate"; func = this.Convert <UInt16>; break; case "Int32": defaultValue = default(Int32); itemTemplateKey = readOnly ? "NumberMetadataValueDataTemplate" : "Int32MetadataValueDataTemplate"; func = this.Convert <Int32>; break; case "UInt32": defaultValue = default(UInt32); itemTemplateKey = readOnly ? "NumberMetadataValueDataTemplate" : "UInt32MetadataValueDataTemplate"; func = this.Convert <UInt32>; break; case "Int64": defaultValue = default(Int64); itemTemplateKey = readOnly ? "NumberMetadataValueDataTemplate" : "Int64MetadataValueDataTemplate"; func = this.Convert <Int64>; break; case "UInt64": defaultValue = default(UInt64); itemTemplateKey = readOnly ? "NumberMetadataValueDataTemplate" : "UInt64MetadataValueDataTemplate"; func = this.Convert <UInt64>; break; case "Single": defaultValue = default(Single); itemTemplateKey = readOnly ? "NumberMetadataValueDataTemplate" : "SingleMetadataValueDataTemplate"; func = this.Convert <Single>; break; case "Double": defaultValue = default(Double); itemTemplateKey = readOnly ? "NumberMetadataValueDataTemplate" : "DoubleMetadataValueDataTemplate"; func = this.Convert <Double>; break; case "Char": defaultValue = 'X'; itemTemplateKey = readOnly ? "StringMetadataValueDataTemplate" : "CharMetadataValueDataTemplate"; func = this.Convert <Char>; break; case "Boolean": defaultValue = default(Boolean); itemTemplateKey = "BooleanMetadataValueDataTemplate"; func = this.Convert <Boolean>; break; case "String": defaultValue = String.Empty; itemTemplateKey = readOnly ? "StringMetadataValueDataTemplate" : "StringMetadataValueDataTemplate"; func = this.Convert <String>; break; case "DateTime": defaultValue = DateTime.UtcNow.Date; itemTemplateKey = readOnly ? "StringMetadataValueDataTemplate" : "DateTimeMetadataValueDataTemplate"; func = this.Convert <DateTime>; break; case "TimeSpan": defaultValue = default(TimeSpan); itemTemplateKey = readOnly ? "StringMetadataValueDataTemplate" : "TimeSpanMetadataValueDataTemplate"; func = this.Convert <TimeSpan>; break; case "Guid": defaultValue = default(Guid); itemTemplateKey = readOnly ? "StringMetadataValueDataTemplate" : "GuidMetadataValueDataTemplate"; func = this.Convert <Guid>; break; case "Point": defaultValue = default(Point); itemTemplateKey = readOnly ? "StringMetadataValueDataTemplate" : "PointMetadataValueDataTemplate"; func = this.Convert <Point>; break; case "Size": defaultValue = default(Size); itemTemplateKey = readOnly ? "StringMetadataValueDataTemplate" : "SizeMetadataValueDataTemplate"; func = this.Convert <Size>; break; case "Rect": defaultValue = default(Rect); itemTemplateKey = readOnly ? "StringMetadataValueDataTemplate" : "RectMetadataValueDataTemplate"; func = this.Convert <Rect>; break; default: Debug.Assert(false); break; } } DataTemplate itemTemplate = null; if (itemTemplateKey != null) { if (readOnly) { itemTemplate = Resources.Get("ReadOnly" + itemTemplateKey) as DataTemplate; } else { itemTemplate = Application.Current.FindResource("KinectStudioPlugin.Writable" + itemTemplateKey) as DataTemplate; } } ObservableCollection <ValueHolder> listCopy = null; if (!readOnly) { listCopy = new ObservableCollection <ValueHolder>(); foreach (object o in list) { listCopy.Add(new ValueHolder(o)); } list = listCopy; } using (WaitCursor waitCursor = new WaitCursor(window)) { MetadataArrayViewerDialog dialog = new MetadataArrayViewerDialog() { Owner = window, Key = key, ItemsSource = list, WindowStartupLocation = WindowStartupLocation.Manual, ItemTemplate = itemTemplate, DefaultValue = defaultValue, IsWritable = !readOnly, }; Point point = Mouse.PrimaryDevice.GetPosition(window); if ((point.X + dialog.Width) > window.ActualWidth) { point.X = window.ActualWidth - dialog.Width; } if ((point.Y + dialog.Height) > window.ActualHeight) { point.Y = window.ActualHeight - dialog.Height; } dialog.Left = point.X + window.Left; dialog.Top = point.Y + window.Top; if (dialog.ShowDialog() == true) { if (metadata != null) { metadata[key] = func(listCopy); } } } } } } }