Change TextBlock foreground color based on the background

耗尽温柔 提交于 2019-12-05 15:39:59
loxxy

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

WPF progress bar with dynamic text & text color update

Quick and dirty method:

Add both the white and grey textblocks, ensuring the white textblock is "on top" of the grey textblock. Bind the text of the white textblock to that of the grey textblock, so they stay the same.

Add an opacity mask to the white textblock, of which the position and/or size (or whatever required!) is bound to the position and/or size of the green rectangle (not sure if that's a templated ProgressBar or a custom control, but either way it could be done).

This would then give the effect of the text over the green bar being white.

You could write an Valueconverter (implement IValueConverter) and pass the BackgroundColor as the converter Parameter. based on the parameter you convert the forground of the Textblock to the desired Value.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!