簡體   English   中英

斑馬條紋列表框項目XAML / C#Windows Phone 7.5

[英]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 =“ Horizo​​ntal” 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM