dataTemplate中边框或stackpanel的动态背景颜色

时间:2012-11-30 11:51:44

标签: windows-phone-7 colors listbox datatemplate

我有这个listboxCode

<ListBox x:Name="listaAdd" FontSize="30" Foreground="{StaticResource PhoneForegroundBrush}" ItemsSource="{Binding ListaMercados}"  Grid.Row="0"   UseLayoutRounding="False" Margin="0,0,0,52"  LayoutUpdated="listaAdd_LayoutUpdated" >
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid HorizontalAlignment="Stretch" Grid.Row="1" Width="480" >
                    <Grid.Background>
                        <SolidColorBrush Color="Transparent"/>
                    </Grid.Background>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="80"/>
                    </Grid.RowDefinitions>
                    <Border x:Name="borda" Tap="Borda_OnTap" Background="Transparent">
                        <ListBoxItem  x:Name="listSelected" 
                                      Grid.Row="1"
                                      IsSelected="True"
                                      VerticalAlignment="Center"  
                                      FontSize="25" 
                                      Content="{Binding Nome}"  
                                      HorizontalContentAlignment="Left" 
                                      Height="80" 
                                      Tap="ListSelected_OnTap" 
                                      FontFamily="Segoe UI" Margin="10,0,0,0" >
                            <ListBoxItem.Foreground>
                                <SolidColorBrush Color="#DEFFFFFF"/>
                            </ListBoxItem.Foreground>
                        </ListBoxItem>
                    </Border>
                    <toolkit:ContextMenuService.ContextMenu>
                        <toolkit:ContextMenu x:Name="subMenulist" Padding="0,0,0,0" FontFamily="Segoe UI" FontSize="32" Margin="0" VerticalAlignment="Center" Grid.RowSpan="1" Grid.ColumnSpan="1" TabNavigation="Local" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Background="White" >
                            <Button Grid.Column="1" 
                                        Content="excluir"  
                                        x:Name="btnExcluirDoSubMenu" 
                                        BorderThickness="0" 
                                        Margin="0,20,0,0" 
                                        Click="btnExcluirDoSubMenu_Click_1" 
                                        Foreground="#FF1A739D" 
                                        FontSize="32" 
                                        HorizontalContentAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" >
                                <Button.Background>
                                    <SolidColorBrush Color="White"/>
                                </Button.Background>
                            </Button>
                            <Button Grid.Column="1" 
                                        Content="compartilhar" 
                                        Margin="0,-20,0,0" 
                                        x:Name="btnShare" 
                                        BorderThickness="0"
                                        Click="btnShare_Click_1" 
                                        Foreground="#FF1A739D" 
                                        FontSize="32" 
                                        HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Background="White"/>
                        </toolkit:ContextMenu>
                    </toolkit:ContextMenuService.ContextMenu>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

我的列表框数据来自招标项目来源,这是我的问题

对于每个新行(列表框)我需要更改两种颜色之间的背景颜色示例: 第一行:蓝色 第二行:红色 第三行:蓝色 第四行:红色 。 。 。 如果我无法访问标签????

中的项目,如何更改背景颜色

1 个答案:

答案 0 :(得分:0)

您可以使用相同的数据绑定原则将列表框项目模板中每个项目的背景属性绑定到颜色。