1

I am using a lot of DatePickers in my C#/WPF application. The people who will be using this app. usually are old and have problems with seeing/reading. I need to change the pale color of the text to something darker so anyone can read the text in the DatePicker.

How and where can I do that?

I am using Visual Studio 2010 and I see only 4 color properties in Brushes section: Background, BorderBrush, Foreground and OpacityMask.

Or I should be doing this with code, set the Brush with code?

Vlad
  • 2,739
  • 7
  • 49
  • 100
  • I would have guessed "Foreground" is the right one? Setting the Brush in code is nothing different than in designer, just that the code is at a different place. – Fildor Jan 15 '18 at 10:59
  • Do they need to read things which are disabled? ;) – Rekshino Jan 15 '18 at 11:00
  • @Rekshino yes. The specific DatePickers are enabled and you can enter a value. Once you have filled the form these date pickers get disabled but should still be in view. – Vlad Jan 15 '18 at 11:35
  • 1
    OK, I see. Then use the solution from Bruno V, it seams to be the only option, or you develop a custom control based on DatePicker – Rekshino Jan 15 '18 at 15:04

1 Answers1

3

The Foreground property sets the text of the DatePicker in an enabled state. When the DatePicker is disabled, the control template adds a semi-transparent overlay to the control.

You can find the default template here. The overlay is defined in the PART_DisabledVisual Grid. To fix your issue, you can copy the entire ControlTemplate in your code and modify the two Rectangles with Fill="#A5FFFFFF" to Fill="Transparent".

Bruno V
  • 1,721
  • 1
  • 14
  • 32
  • Bruno, I'm trying to implement the solution you recommended but I've been unable to do so thus far. I've never used a template or control template before, so I've been trying to figure that out first. It seems like the solution is to create in the XAML and define Styles there; however, when I try to copy-paste the style in the link you provided and running it as-is, the control turns into a broken version of the DatePicker. It does not look like it did originally. Could you provide additional insight? – Joshua Granger Apr 06 '19 at 01:40
  • 1
    I believe your approach is correct but Microsofts default templates are not up to date. You can extract the default Control Template for the `DatePicker` in Visual Studio as described [here](https://stackoverflow.com/questions/8825030/how-to-extract-default-control-template-in-visual-studio). Modifying the DisabledVisual colors as described in my answer should lead to the correct result. – Bruno V Apr 08 '19 at 10:19