[リスト アイテムの表現]をダウンロードする。
<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>
Imports System.Reflection
Class MainWindow
Public Sub New()
' この呼び出しはデザイナーで必要です。
InitializeComponent()
Dim ColorList = From C In GetType(Colors).GetProperties() _
Select New ColorItem With {.Name = C.Name, .Color = CType(C.GetValue(Nothing, Nothing), Color)}
listColors.ItemsSource = ColorList
End Sub
End Class
Public Class ColorItem
Private _Name As String
Private _Color As Color
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Public Property Color() As Color
Get
Return _Color
End Get
Set(ByVal value As Color)
_Color = value
End Set
End Property
Public ReadOnly Property Brush() As Brush
Get
Return New SolidColorBrush(_Color)
End Get
End Property
End Class