2017-02-20 84 views
0

我我的組合框綁定靜態的方式。選擇ComboBox項編程C#

當我設置字符串值這是我從項目對象(從服務方法)獲得,例如item.AssignmentType =「XYZ」我想使它可選擇的組合框。 我試過以下,但不工作

<ComboBoxItem Content="abc"/> 
<ComboBoxItem Content="xyz"/> 
<ComboBoxItem Content="pqrs"/> 

string assignmenttype = item.AssignmentType.ToString(); 
AssignmentTypeCombobox.SelectedIndex = 
AssignmentTypeCombobox.Items.IndexOf(assignmenttype); 

請給我解決

+0

[Combobox.SelectedItem](https://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selecteditem(v = vs.110)。 ASPX) – bansi

+0

試試看'AssignmentTypeCombobox.Text = 「XYZ」' – bansi

+0

但是, 「文本」 屬性不UWP組合框 – Murali

回答

0

可以綁定一切senseful到一個ComboBox。我會推薦一些集合類(的ObservableCollection)的。您需要到DataContext設置爲此收集和!您現在可以走了。有關更多詳細信息,請查看: Bind collection to combobox