In WPF ComboBox does not have SelectedText property.
Is there a way to achieve the same functionality as TextBox SelectedText has in WPF
You can get access to the ComboBox's TextBox by using:
var edit = (TextBox)myCombo.Template.FindName("PART_EditableTextBox", myCombo);
Then you can access the SelectedText property of that TextBox:
var selectedText = edit.SelectedText;
Because WPF is "lookless" you can display your combobox items in any manner you wish. there may or may not be a text item.
MyCombo.SelectedText
doesn't make any sense if you are, for example, display icons in there.
What you want is ComboBox.SelectedItem
and then access your object. for example, if you are using a backing list of "People" objects.... MyComboBox.SelectedItem.PersonName
typically, the SelectedItem is databound to your object model or to another control.
Use this:
ComboBoxItem Item = (ComboBoxItem) YourComboBoxName.SelectedValue;
Then this:
Console.WriteLine(Item.Content);
Another approach:
(string)comboBox.SelectedItem.GetType().GetProperty(DisplayMemberPath).GetValue(comboBox.SelectedItem);
There is no property called the selectedText but you can achive that by ComboBox.SelectedValue.ToString()
method. It's because the values of an combobox is by default of the type Object so we have to suitably typecast it.