Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Custom ComboBox question

$
0
0

Hello

Im relative new to WPF. Im trying to implement a custom ComboBox, a base class for ComboBoxes which display enum-members. Derived classes should easily be able to set the text which represents the enum values.

This is what I did so far (more or less, I removed the irrelevant code):

public class EnumComboBox<T> : System.Windows.Controls.ComboBox
		where T : struct
	{
		protected virtual string FormatEnum(T value)
		{
			return "Test " + value.ToString();
		}

		protected override void PrepareContainerForItemOverride(System.Windows.DependencyObject element, object item)
		{
			base.PrepareContainerForItemOverride(element, item);
			if (!(item is T))
				return;

			T value = (T)item;
			string text = this.FormatEnum(value);
			element.SetCurrentValue(ContentControl.ContentProperty, text);
		}
	}


This displays the string returned by FormatEnum for each enum value in the dropdownlist of the ComboBox as I want it to. The problem is that I cant figure out how to specify how the selected item is displayed. Can somebody please give me a hint how to do this?


https://fraktalysator.codeplex.com


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>