我需要以不同的方式(例如用不同的颜色)标记ListBox中的第一项。如果我listbox
有一种方法可以以编程方式为红色中的第一项着色。
列表框:
List<CartItem> CartListItem = CartItem.getListOfCartItems(myCart, Items);
dgProduct.ItemsSource = Items;
Xaml
<ListBox Name="dgProduct" HorizontalContentAlignment="Stretch" Margin="0,41,10,0" Grid.RowSpan="3"
">
<ListBox.ItemTemplate>
<DataTemplate>
.
.
.
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
您可以在AlternationCount
上设置ListBox
,然后使用StyleTrigger
for index 0
。
<ListBox Name="dgProduct"
HorizontalContentAlignment="Stretch"
Margin="0,41,10,0"
Grid.RowSpan="3"
AlternationCount="1000">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Background" Value="Transparent"/>
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
.
.
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句