XAML:
<ComboBox Height="23" HorizontalAlignment="Left" Margin="84,51,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Text}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" Height="100" />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
<ComboBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="IsEnabled" Value="{Binding CanSelect}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
のC#:
public class Item
{
public string Text { get; set; }
public bool CanSelect { get; set; }
}
public class SelectableItem : Item
{
public SelectableItem()
{
CanSelect = true;
}
}
public class Header : Item
{
}
// inside constructor or wherever:
var items = new Item[] {
new Header() { Text = "Header1"},
new SelectableItem() { Text = "ComboboxItem"},
new SelectableItem() { Text = "ComboboxItem"},
new SelectableItem() { Text = "ComboboxItem"},
new SelectableItem() { Text = "ComboboxItem"},
new SelectableItem() { Text = "ComboboxItem"},
new Header() { Text = "Header2"},
new SelectableItem() { Text = "ComboboxItem"},
new SelectableItem() { Text = "ComboboxItem"},
new Header() { Text = "Header3"},
new SelectableItem() { Text = "ComboboxItem"},
new SelectableItem() { Text = "ComboboxItem"},
new SelectableItem() { Text = "ComboboxItem"},
new SelectableItem() { Text = "ComboboxItem"},
new SelectableItem() { Text = "ComboboxItem"},
new SelectableItem() { Text = "ComboboxItem"}
};
comboBox1.ItemsSource = items;