将列表框控件中选定的字体颜色设置为与未选定的字体颜色不同
我发现字体颜色来自列表框或组合框的内容(即控件模板之外)。 当未选择项目时,我希望在白色背景上显示黑色文本,而当选择项目时,我希望在白色背景上显示黑色文本。 不幸的是我无法弄清楚如何更改文本颜色。 我正在努力寻找在选定和未选定的背景颜色之间形成鲜明对比的颜色。
检查了 Silverlight 3,但您似乎也无法在那里执行此操作。
I've found that the font colour comes from the content (ie outside of the controltemplate) of a listbox or combobox. I'd like to have black text on white background when the items are unselected, and when selected would like black background with white text.
unfortunately I've not been able to figure out how to change the text colour. I'm struggling to find colours that contrast well between the selected and unselected background colour.
checked in Silverlight 3 and you dont seem able to do it there either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法在 Silverlight 4 中为在 AutoCompleteBox 下弹出的 ListBox 做类似的事情,但它是大量的 Binging 和 XAML 强奸。
基本上,您必须创建一个 ListBoxItem 样式并在其下强制执行一些控件模板 hacking。 然后您可以将其应用到您的列表框上,它应该可以工作。
我刚刚从我正在处理的项目中复制了相关代码,因此您必须对其进行一些调整,但它确实会更改鼠标悬停时的字体和选择矩形颜色,因此应该是一个很好的开始。
它应该直接位于 UserControl.Resources 下,您就可以绑定它了。
如果您成功或需要更多解释,请告诉我!
I managed to do a similar thing in Silverlight 4 for a ListBox popping under an AutoCompleteBox, but it was copious amounts of Binging and XAML rape.
Basically you have to create a ListBoxItem style and force some control template hackery under it. This then you can apply on your ListBox and it should work.
I just copied the relevant code from the project I'm working on so you'll have to tweak it a bit, but it does change both the font and the selection rectangle colour on mouse over, so should be a great start.
It should go straight under UserControl.Resources and you'll be ready to bind it.
Let me know if you managed or need more explanation!