![](/img/trans.png)
[英]How to dynamically add items to ListBox in Windows Phone 7/C#
[英]Zebra Striping Listbox Items XAML/C# Windows Phone 7.5
我想斑马处理一个列表框,该列表框是从搜索返回的对象的可观察集合中生成的。
代码像这样
<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>
我该如何剥离它,以使第一个<stackpanel>
为黄色,第二个为白色,第三个为黄色等等?
谢谢,丹尼
创建一个将在列表框中使用的自定义控件。 其中将包含:
<StackPanel Orientation =“ Horizontal” Margin =“ 0,0,0,17”>
<Border 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}”前景=“#AFA7A0” />
</ Border>
</ StackPanel>
在可观察的收集项目中维护索引。
将列表框绑定到可观察的集合。
在自定义控件中创建bordercolor属性,并根据索引值(偶/奇)对其进行初始化
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.