如何在 windows phone 8 中的字符串数组中的每个列表框项目上应用背景颜色?

How to apply background color on each listbox item from string array in windows phone 8?

我正在开发一个应用程序,其中有一个列表框包含 3-4 items.I 想要应用包含颜色值的字符串数组中的背景颜色。谁能建议我如何应用数组中的颜色。我做了一些研究,发现 System.Drawing 在 c# 中有帮助,但在 wp8 中不可用。我的列表框xaml代码如下:

<Grid x:Name="ContentPanel"
          Grid.Row="1"
          Margin="0,10,0,0">
        <ListBox x:Name="SampleList"
                     Margin="0,10,0,0"
                     ItemContainerStyle="{StaticResource GenericListBoxContainerStyle}"
                     toolkit:TiltEffect.IsTiltEnabled="True"
                      >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border BorderBrush="White" BorderThickness="2">
                        <Grid Margin="0,2,0,2"
          toolkit:TiltEffect.IsTiltEnabled="True">
                            <StackPanel 
                    Margin="0,8,0,8">
                                <TextBlock Text="{Binding Value}"
                       Margin="10"
                       Style="{StaticResource HeaderContentStyle}"
                       Foreground="White"
                       FontFamily="/Fonts/lte50331.ttf#Frutiger LT 55 Roman"/>

                            </StackPanel>
                        </Grid>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Grid>

并且 C# 代码只包含将列表对象的值添加到项目源

SampleList.ItemSource=list

和包含颜色的字符串数组

string[] colors={hex_value1,hex_value2,hex_value3}

请推荐。

将 Colors 数组添加到列表中,然后将其绑定到边框背景。

 public class item()
       {
       private string name;
       private string background;
       public string Name
     {
    get
     {
    return this.name;
     }
    set 
    {
    this.name= value;
   }
  }
   public string BackgroundColor
   {
   get
   {
    return this.background;
   }
   set 
   {
    this.background= value;
}
}
  List<item> Itemlist= new List<item>()
      for(int i=0;i<Itemlist.Count;i++)
          {
     Itemlist[i].BackgroundColor=Colorsarray[i];
         }
   SampleList.ItemSource=Itemlist;

    In xaml 

    Background="{Binding BackgroundColor}"

对于列表中的每个项目,添加:

public string Color { get; set; }

设置 item.Color = 每种颜色;

在您的 xaml 中,添加:

Background="{Binding Color}"