Displaying selected item of a wpf ComboBox in a messagebox

I have the following ComboBox in XAML Code

<ComboBox Name="angleComboBox" SelectionChanged="angleComboBox_SelectionChanged">

along with its following event handler below

private void angleComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            string selection = angleComboBox.SelectionBoxItem as string;

What I am trying to do is get the messagebox to display whatever I am selecting in the combobox for example a messagebox display the word Degree when Degree is selected from the ComboBox. For some reason selecting Degree in the ComboBox yields and empty message box and selecting Radian yields a messagebox with the word Degree instead of Radians.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


try using the selected item instead. it's a comboBoxItem so you're after the content property of that. I've implemented the change to the handler for you below:


        private void angleComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            ComboBoxItem cbi = angleComboBox.SelectedItem as ComboBoxItem;
            string selection = cbi.Content.ToString();

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hi, you've to process e.AddedItems and e.RemovedItems correctly. SelectionBoxItem will only show the current item, but it's set to the current value at the time the event is fired.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.