Question:OK so this is definitely a newbie question that unfortunately could not figure/find the answer to.
Essentially binding a list of objects to a Combobox, when the
Disabledproperty on the object is set to true I want the text colour of the Combobox item to be set to gray.
This is what I have so far:
Combobox item datatype
Solution: It looks like in future I need to test the example code before puttin it up – our actual code had the
Disabledproperty set as a
readonlywhich must mess with WPF binding. Changing it to public set and get solved the first issue of not seeing it greyed out! It would seem staring at a problem for so long blinds you and it really is that simple. As for graying out the selected item I will try it out and see.
Best Answer:The last item in the dropdown already has its text grayed out, so I assume you’re asking about the selected item. The
ComboBoxuses separate data templates for the selected item and the items in the dropdown. You can use a
DataTemplateSelectorto set both.
DataTemplatedefinitions, but these tend to grow apart in production code.
- Can I use a different Template for the selected item in a WPF ComboBox than for the items in the dropdown part?
If you have better answer, please add a comment about this, thank you!