Search code examples
c#wpfsavecolor-picker

Error message "cannot implicitly convert type 'system.drawing.color' to 'system.windows.media.color'"


I am struggling with some WPF issues. This is just one of them:

{backgroundColor.SelectedColor = Properties.Settings.Default.backgroundColorSt;}

When I write this into my initiliaze() section, I face an error like:

cannot implicitly convert type 'system.drawing.color' to 'system.windows.media.color'

How can I convert System.Drawing.Color into System.Windows:Media.Color to save the color which I choose from colorPicker?


Solution

  • Don't use the type System.Drawing.Color for your backgroundColorSt setting in the first place. Instead, use System.Windows.Media.Color.

    In the Settings page of your project properties,

    • go to the backgroundColorSt line
    • click the Type ComboBox,
    • choose Browse...,
    • select the PresentationCore assembly,
    • then the namespace System.Windows.Media,
    • then the type Color.