WPF Binding My.Settings collection to Combobox items

前端 未结 5 1923
长情又很酷
长情又很酷 2021-02-15 16:18

I\'m VERY new to WPF, and still trying to wrap my head around binding in XAML.

I\'d like to populate a combobox with the values of a string collection in my.settings. I

5条回答
  •  孤城傲影
    2021-02-15 17:00

    Yes, you can (and should for the most part) declare bindings in XAML, since that's one of the most powerful features in WPF.

    In your case, to bind the ComboBox to one of your custom settings you would use the following XAML:

    
        
            
        
    
    

    Notice the following aspects:

    • We declared an XML namespace with the prefix 'p' that points to the .NET namespace where the 'Settings' class lives in order to refer to it in XAML
    • We used the markup extension '{Binding}' in order to declare a binding in XAML
    • We used the markup extension 'Static' in order to indicate that we want to refer to a static ('shared' in VB) class member in XAML

提交回复
热议问题