Posts

Showing posts from November, 2011

Binding ENUM to WPF control - ComboBox

I believe, I explored quite a bit on finding the best approach for my requirement of binding Enum to WPF ComboBox and thought to share the gradual steps here for a one-stop place which hopefully will help similar minded technical enthusiast .. The simplest approach: You want to just bind Enum as it appears (verbatim) to the WPF combo .. Let's define a sample enum as follows: namespace {    public enum TestEnum    {       String1,       String2,       String3,       String4    } } All we now need is a way to leverage Enum - GetValues method to provide a list of values that lets you bind directly to the ComboBox via ItemSource. < ObjectDataProvider x : Key ="dataFromEnum" MethodName ="GetValues" ObjectType ="{ x : Type sys : Enum }" > < ObjectDataProvider.MethodParameters > < x : Type TypeName ="local:TestEnum" /> </ ObjectDataProvider.MethodParameters > </ ObjectDataProvider > Reference URL: ht