2016-05-03 27 views
0

Ich habe zu diesem Thema suchen, aber nur die Notwendigkeit gefunden, verschiedene Spalten mit einem ComboBoxItem füllen. Was ich brauche, ist eine Liste einer einzelnen Spalte, die in verschiedenen Spalten gekapselt ist, um die Gesamtlänge der ComboBox zu verkürzen und zusätzlich einige Header zu setzen, um Abschnitte zu begrenzen, um die Suche nach einem Element zu erleichtern. Hier ist ein Beispiel für wath ich suche:Wie erstellt man ein Dropdown ComboBox in mehreren Spalten?

multi columns ComboBox

Ich bin mit grid.columns Definitionen innerhalb des Popup-Tag in einem ComboBox Stil vermasselt, aber ich bin nicht das richtige Ergebnis.

Danke.

Antwort

0

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; 
Verwandte Themen