Je souhaite avoir une liste déroulante wpf qui affiche la zone de liste déroulante avec les options regroupées sous un titre comme le comportement <optgroup> en html. Est-ce que quelqu'un a l'air de faire quelque chose comme ça avant?WPF ComboBox "comportement de type de groupe d'options (optGroup)"
1
A
Répondre
4
Voir How to: Sort and Group Data Using a View in XAML. Vous appliquez un grouping au CollectionView pour vos données, puis définissez GroupStyle sur le ComboBox. Fait entièrement XAML, il ressemblerait à ceci:
<StackPanel>
<StackPanel.Resources>
<CollectionViewSource x:Key="groupedData" Source="{Binding}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Length"/>
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</StackPanel.Resources>
<ComboBox ItemsSource="{Binding Source={StaticResource groupedData}}">
<ItemsControl.GroupStyle>
<x:Static Member="GroupStyle.Default"/>
</ItemsControl.GroupStyle>
</ComboBox>
</StackPanel>
Ou vous pouvez appliquer le regroupement dans le code:
this.DataContext = new List<string>() { "foo", "barr", "baz", "fizz" };
var cv = CollectionViewSource.GetDefaultView(this.DataContext);
cv.GroupDescriptions.Add(new PropertyGroupDescription("Length"));
Et utiliser la vue collection par défaut en XAML:
<ComboBox ItemsSource="{Binding}">
<ItemsControl.GroupStyle>
<x:Static Member="GroupStyle.Default"/>
</ItemsControl.GroupStyle>
</ComboBox>
Vous pourrait personnaliser l'apparence des données groupées en fournissant un GroupStyle personnalisé avec votre propre HeaderTemplate.
Questions connexes
- 1. Comment désactiver optgroup de combobox
- 2. ComboBox étrange comportement - WPF
- 3. Comportement de tabulation de l'élément ComboBox WPF
- 4. Composant personnalisé avec comportement de type combobox
- 5. Silverlight 3 Comportement de survol de Combobox
- 6. Comportement attaché ComboBox Silverlight
- 7. WPF XAML ComboBox Largeur
- 8. Modification du comportement de ComboBox modifiable
- 9. WPF - Problème de liaison ComboBox
- 10. Définir SelectedItem de WPF ComboBox
- 11. Propriété IsEditable de WPF combobox
- 12. WPF: Articles ComboBox Max?
- 13. Comportement dynamique ComboBox Ext JS
- 14. WPF ComboBox SelectedItem enfer
- 15. WPF ComboBox SelectedItem
- 16. Comportement de liaison étrange dans WPF
- 17. WPF ComboBox Liaison bidirectionnelle
- 18. FF3 Comportement AwesomeBar dans WPF
- 19. ComboBox personnalisé lié au type dérivé de ComboBox
- 20. Comportement de dessin WPF déroutant
- 21. Aide de liaison de données WPF ComboBox?
- 22. Liaison Combobox vers XML (wpf)
- 23. WPF Combobox Liaison d'enregistrements SelectionChanged
- 24. Contrôle de type ruban dans WPF
- 25. WPF Comportement de la souris lorsque ComboBox est mis au point
- 26. wpf dataagrid textbox + combobox
- 27. Liaison Combobox WPF Question
- 28. WPF ComboBox DropDown Placement
- 29. WPF: Combobox dans TreeviewItem
- 30. ComboBox WPF Reliure Immuable