Beispiel #1
0
		static void OnEnumTypePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
		{
			Type enumType = e.NewValue as Type;
			if (enumType != null && enumType.IsEnum) {
				ComboBox comboBox = o as ComboBox;
				if (comboBox != null) {
					comboBox.SelectedValuePath = "Tag";
					comboBox.Items.Clear();
					foreach (FieldInfo field in enumType.GetFields()) {
						if (field.IsStatic) {
							ComboBoxItem item = new ComboBoxItem();
							item.Tag = field.GetValue(null);
							string description = GetDescription(field);
							item.SetValueToExtension(ComboBoxItem.ContentProperty, new StringParseExtension(description));
							comboBox.Items.Add(item);
						}
					}
				}
				RadioButtonGroup rbg = o as RadioButtonGroup;
				if (rbg != null) {
					rbg.Items.Clear();
					foreach (FieldInfo field in enumType.GetFields()) {
						if (field.IsStatic) {
							RadioButton b = new RadioButton();
							b.Tag = field.GetValue(null);
							string description = GetDescription(field);
							b.SetValueToExtension(RadioButton.ContentProperty, new StringParseExtension(description));
							rbg.Items.Add(b);
						}
					}
				}
			}
		}