If I define a color with e.g. "#hexCodes" then I can use it in legendes without any problems.
If I define a color via its name then I cannot used it as background color without an additional #.
Is this intended?
Yes, this is intended. I agree that this not very consistent. If it confused you, you could use a # in every case.
Based on that problem I have to define the background color twice (depending on the context)
Here, I am confused. Why do you have to define the background color twice ?
and I have to know the correct hex codes too.
And why do you have to know the correct hex code ?
I think you should give us an example so that we fully understand the issue.
Thanks !