<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="190" Width="670"> <Grid x:Name="LayoutRoot" > <ListBox x:Name="listColors" Height="120" > <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate> <Grid Width="100"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <TextBlock Grid.Row="0" Text="{Binding Name}" /> <Ellipse Grid.Row="1" Fill="{Binding Brush}" Height="80"/> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid> </Window>
using System.Linq; using System.Windows; using System.Windows.Media; namespace ListItems { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var ColorList = from c in typeof(Colors).GetProperties() select new ColorItem { Name = c.Name, Color = (Color)c.GetValue(null, null) }; listColors.ItemsSource = ColorList; } } public class ColorItem { public string Name { get; set; } public Color Color { get; set; } public Brush Brush { get { return new SolidColorBrush(Color); } } } }