你想要一个MultiSelectList 还是一个ListPicker?您是否希望用户能够选择不止一种颜色?这是一个使用 ListPicker 的示例。要获得颜色,您必须自己创建颜色。这是使用强调色的示例
ListPicker 的 xaml:
<toolkit:ListPicker x:Name="ColorPicker" ExpansionMode="FullScreenOnly"
FullModeHeader="COLOR"
Visibility="Collapsed"
ItemsSource="{Binding Brushes}"
SelectedItem="{Binding SelectedBrush, Mode=TwoWay}">
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<StackPanel Margin="0 20" Orientation="Horizontal">
<Rectangle Width="42" Height="42" Fill="{Binding Brush}"
Stroke="{StaticResource PhoneForegroundBrush}"
HorizontalAlignment="Left"/>
<TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextExtraLargeStyle}"
HorizontalAlignment="Center" Margin="5,0"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
以及生成颜色集合的代码:
private IList<ColorItem> CreateBrushes()
{
var brushes = new List<ColorItem>
{
new ColorItem { Brush = new SolidColorBrush(Color.FromArgb(255,27,161,226)), Name = "blue" },
new ColorItem { Brush = new SolidColorBrush(Color.FromArgb(255,160,80,0)), Name = "brown" },
new ColorItem { Brush = new SolidColorBrush(Color.FromArgb(255, 51,153,51)), Name = "green" },
new ColorItem { Brush = new SolidColorBrush(Color.FromArgb(255,162,193,57)), Name = "lime" },
new ColorItem { Brush = new SolidColorBrush(Color.FromArgb(255,216,0,115)), Name = "magenta" },
new ColorItem { Brush = new SolidColorBrush(Color.FromArgb(255,240,150,9)), Name = "mango" },
new ColorItem { Brush = new SolidColorBrush(Color.FromArgb(255,230,113,184)), Name = "pink" },
new ColorItem { Brush = new SolidColorBrush(Color.FromArgb(255,162,0,255)), Name = "purple" },
new ColorItem { Brush = new SolidColorBrush(Color.FromArgb(255,229,20,0)), Name = "red" },
new ColorItem { Brush = new SolidColorBrush(Color.FromArgb(255,0,171,169)), Name = "teal" },
};
return brushes;
}
public class ColorItem
{
public SolidColorBrush Brush { get; set; }
public string Name { get; set; }
}
您还可以使用反射来收集颜色。
Type t = typeof(Colors);
var properties = t.GetProperties();
List<ColorItem> items = new List<ColorItem>();
for (int i = 0; i < properties.Length; i++)
{
var property = properties[i];
items.Add(new ColorItem
{
Name = property.Name,
Color = new SolidColorBrush((Color)property.GetValue(null, null))
});
}