开发者

Change ListBoxItem Background color from within ItemTemplate?

I've searched and came up empty, therefore I'm asking.

I found how to change Backg开发者_如何学Cround and Highlight Background color of ListBoxItem using ItemContainerStyle.

But I'd like to change these 2 colors based on data from within my DataTemplate for Items.

Is that possible?


I think it would be possible to do it with a list, I've already done this kind of thing using Datagrids. Christian Mosers offers a good and understandable way to do that with DataGrid, you can easily use his datatemplates for ListBoxItems: http://www.wpftutorial.net/DataGrid.html#rowDetails

EDIT

Have you tried to set a style aiming for ListBoxItems in your listbox's resources?

<ListBox.Resources>
   <Style TargetType="{x:Type ListBoxItem}">
      <Setter Property="Background" Value="Blue" />
   </Style>
</ListBox.Resources/>

This should set all your items' bg to Blue


I came up with a solution later on.

The only reasonable way is to define/redefine Listbox Control template.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜