Silverlight: Default value in Combobox

后端 未结 3 795
名媛妹妹
名媛妹妹 2021-01-05 09:22

I would like to display a default text in the combobox. For example, \"Choose a person\" message. could you please help me out.

Please note that I am using databindi

3条回答
  •  轮回少年
    2021-01-05 09:26

    Just do this:

    theComboBox.SelectedItem  = yourDataItem;
    

    alternatively, set the selected index:

    theComboBox.SelectedIndex = 0;
    

    Edit

    If ItemSource is bound, you want to override the combo's DataContextChanged and then use one of the above lines to set the index/selected item.


    However, if you don't want the default text to be selectable, you will have to do something along the lines of this.

提交回复
热议问题