Binding a ComboBox to an enum nested in a class

后端 未结 2 2119
孤独总比滥情好
孤独总比滥情好 2020-12-03 18:09

I have been going crazy with binding a combobox to an enum typed property of a class, where the enum itself is declared in that same class.

I am trying to follow th

2条回答
  •  青春惊慌失措
    2020-12-03 18:47

    Another way of getting the enum values for use as a data source:

    
        
            
                
            
        
    
    
    ...
    
    ItemsSource="{Binding Source={StaticResource TestValues}}"
    

    Note that you still need the Type2Extension because of weirdness with TypeExtension and nested types. But you wouldn't need the extra custom markup extension. This way is better if you'll be using the list in multiple places, as you can declare it in your App.xaml resources.

提交回复
热议问题