2012-11-30 84 views
0

邊框或StackPanel中我有這個listboxCode動態背景顏色裏面的DataTemplate

<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> 

我的列表框中的數據從一個招標項目源的到來,這裏的(列表框的)我的問題

爲每個新行例如: 第一行:藍色 第二行:紅色 第三行:藍色 第四行:紅色 。 。 。 如果我無法訪問標籤內的項目,我如何更改背景顏色?

回答

0

您可以使用相同的數據綁定原則將列表框項目模板中每個項目的背景屬性綁定到Color。