How to set the SystemColors.HighlightBrushKey in WPF with a Converter

Deadly 提交于 2019-12-04 20:53:07
Kent Boogaart

The problem is in this binding:

Color="{Binding Background, Converter={StaticResource SelectionBackgroundConverter}}"

There is no Source, and the Background property won't exist in the current context. Change it to this:

Color="{Binding Source={x:Static SystemColors.HighlightBrush}, Converter={StaticResource SelectionBackgroundConverter}}"

And your converter will be called. You have bugs in your converter though, but that should get you started. Also consider:

  • freezing the Brush
  • caching the Brush (if you do this a lot in your app)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!