Casting SelectedItem of WPF Combobox to Color causes exception
- by Nick Udell
I have a combobox databound to the available system colors. When the user selects a color the following code is fired:
private void cboFontColour_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Color colour = (Color)(cboFontColour.SelectedItem);
}
This throws a Casting Exception with the following message: "Specified cast is not valid." When I hover over cboFontColour.SelectedItem in the debugger, it is always a Color object.
I do not understand why the system seemingly cannot cast from Color to Color, any help would be much obliged.