[英]Zebra Striping Listbox Items XAML/C# Windows Phone 7.5
I want to zebra stipe a Listbox that is generated from an observable collection of objects returned from a search. 我想斑马处理一个列表框,该列表框是从搜索返回的对象的可观察集合中生成的。
The code is like so 代码像这样
<ListBox x:Name="searchResultsListBox" Margin="0, 115, -12, 0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<StackPanel Width="411">
<TextBlock Text="{Binding Registration}" Margin="12, -6, 12, 0" TextWrapping="Wrap" FontSize="30" Foreground="White"/>
<TextBlock Text="{Binding SalePrice}" Margin="12, -6, 12, 0" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" Foreground="#AFA7A0"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
How would I go about striping it so that the first <stackpanel>
was yellow, the second white and the third yellow again etc etc? 我该如何剥离它,以使第一个
<stackpanel>
为黄色,第二个为白色,第三个为黄色等等?
Thanks, Danny. 谢谢,丹尼
Create a custom control which you will use inside your listbox. 创建一个将在列表框中使用的自定义控件。 This will contain:
其中将包含:
<StackPanel Orientation="Horizontal" Margin="0,0,0,17"> <StackPanel Orientation =“ Horizontal” Margin =“ 0,0,0,17”>
<Border Width="411"> <Border Width =“ 411”>
<TextBlock Text="{Binding Registration}" Margin="12, -6, 12, 0" TextWrapping="Wrap" FontSize="30" Foreground="White"/> <TextBlock Text =“ {Binding Registration}” Margin =“ 12,-6,12,0” TextWrapping =“ Wrap” FontSize =“ 30” Foreground =“ White” />
<TextBlock Text="{Binding SalePrice}" Margin="12, -6, 12, 0" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" Foreground="#AFA7A0"/> <TextBlock Text =“ {Binding SalePrice}” Margin =“ 12,-6,12,0” TextWrapping =“ Wrap” Style =“ {StaticResource PhoneTextSubtleStyle}”前景=“#AFA7A0” />
</Border > </ Border>
</StackPanel> </ StackPanel>
Maintain index in the observable collection items. 在可观察的收集项目中维护索引。
Bind the list box to the observable collection. 将列表框绑定到可观察的集合。
Create a bordercolor property in the custom control and initialize it on the basis of index value (even/odd) 在自定义控件中创建bordercolor属性,并根据索引值(偶/奇)对其进行初始化
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.