Databinding an enum property to a ComboBox in WPF

后端 未结 13 1500
北海茫月
北海茫月 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:28

    you can consider something like that:

    1. define a style for textblock, or any other control you want to use to display your enum:

      
      
    2. define your style for ComboBoxItem

      
      
    3. add a combobox and load it with your enum values:

      
          
              
                  Value1
              
          
      
      

    if your enum is large, you can of course do the same in code, sparing a lot of typing. i like that approach, since it makes localization easy - you define all the templates once, and then, you only update your string resource files.

提交回复
热议问题