Databinding an enum property to a ComboBox in WPF

后端 未结 13 1492
北海茫月
北海茫月 2020-11-22 15:46

As an example take the following code:

public enum ExampleEnum { FooBar, BarFoo }

public class ExampleClass : INotifyPropertyChanged
{
    private ExampleEn         


        
13条回答
  •  情深已故
    2020-11-22 16:25

    If you are using a MVVM, based on @rudigrobler answer you can do the following:

    Add the following property to the ViewModel class

    public Array ExampleEnumValues => Enum.GetValues(typeof(ExampleEnum));
    

    Then in the XAML do the following:

    
    

提交回复
热议问题