Silverlight Listbox Item Style

蹲街弑〆低调 提交于 2019-12-06 09:42:27

Change the ContentPresenter in you template to a ContentControl which has a Foreground property you can TemplateBind.

I tried your scenario. By default the content of the default listitem is a string which is black. A listbox item has a foreground property you can set but I'm not sure either where it is in the template. They did something special for strings to use the foreground but didn't expose it in the template. A hack you might want to try is, if you know you will always have string content, to replace the contentpresenter of the controltemplate with a textblock, which does have the forground. (To edit the ListItem's template right click on it in Blend3 and go to Edit Template, Edit a Copy, and modify the new Style}

<ContentPresenter x:Name="contentPresenter" 
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}" Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />

to

<TextBlock x:Name="contentPresenter" Foreground="{TemplateBinding Foreground}"
Text="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding 
HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" />

I added the TemplateBinding for Text and Foreground. You should be able to manipulate the foreground in the visual states to get the right states look disabled, selected, etc. I hope this helps.

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