I thought some of you may like to share in the fun I have been having playing around with colors in the 'QR code' applet I have been developing for the German Cologne conference.
Although it is only a small app - not many code and script lines, in fact it uses some quite neat and modern ways of doing things. I even surprised myself.
Have a look at this included short video to see how it now works, and then we can discuss further.
The parts of the app I have added since I last posted, are those to support the two new drop lists (combo boxes) with 150 colors available for selection.
The code uses Reflection to find all of the named color 'properties' in the System.Drawing namespace. these are then converted by code to Names and Colors.
The two drop lists in fact use the same 'script and code behind' - so once you have cracked one you have done the other too - nice.
The issues I tried to solve were around the strength (or darkness) of the colours, and getting a text name and color to show on each different background colour. There was need for a little algorithm - Alwyn taught me to approach things this way (shown in the algorithm) ;-0) Thanks Alwyn.
Oh! I also nearly forgot to say that I also use LINQ to grade the colors - dark to light in the lists. Lets look at the part of the drop list where it changes from dark to lighter, and the text shown swaps from white to black - check below :-
Okay then, getting there, just a bit further ............
I have added a 'Converter' to the XAML script which styles the 'ComboBoxItem' GUI elements.
Here it is below, and basically it takes the Background property value and returns either a Black or a White as Foreground color, depending on the 'darkness' of the background color. Check this out :-
Sorry - when I took this screen shot I had not as then sorted the colors into order - Dark to Light.
All the interactivity is done in WPF and by 'data binding' in the XAML script.
And finally, the nice part played by LINQ - the few lines in the next image place the color related items into order - check lines 128 through 135 :-
The selected items from the two drop lists are held as public properties on the Window class used. These behave as they should, as far as notifying property changes.
It is quite amazing just how much of this simple sample is modern style code/script, and would not really have been recognisable five years ago. And I know I for one, would NOT have been able to tackle this test 'task'sample back then.
The question "is the result worth all the hard work to keep up with changes" needs to be asked and fairly answered I feel.
Oh! If you would like to download the working EXE file then here is the link :-
P.S. the attendees at my sessions, and the Cologne conference will get all of the supporting material - code, script, projects and solutions, as well as eNotes. It is great fun! We will have a good time I feel !!
You have probably forgotten - BUT - it was you who first drew my attention to that fact that we could bind across "properties / attributes" in the same Control element. You helped me get my first similar sample going - however, I hand coded the color items back then. And no nifty color algorithms back then.
So thanks for the 'leg up' as they say.
Have a nice day - it lovely and bright and sunny in Newport - if a bit on the 'chilly' side!