Search code examples
wpfcolorstextblockforeground

Change TextBlock foreground color based on the background


I'm looking for a simple way to change the foreground color of a TextBlock based on the color of what is behind it, so that it is more readable. Since an image is more explicit than words, here's what I want:

I assume it could be done with a custom shader effect, but I have no idea how to create it... Anyway, perhaps there is a simpler solution.

Any idea would be welcome!


Solution

  • Assuming the above is a progressbar, here is a great solution:

    WPF progress bar with dynamic text & text color update