I want to make a ComboBox
with 0-N Separators
I was able to do this with CompositeCollection
like so
<ComboBox.ItemsSource>
<CompositeCollection>
<CollectionContainer Collection ={Binding mysrc1}/>
<ComboBoxItem IsEnabled = "False">
<Separator Background = "White" Height=10/>
</ComboBoxItem>
<CollectionContainer Collection ={Binding mysrc2}/>
<ComboBoxItem IsEnabled = "False">
<Separator Background = "White" Height=10/>
</ComboBoxItem>
</CompositeCollection>
</ComboBox.ItemsSource>
But this is kind of clunky and with a lot of code duplication but in .View
and in .ViewModel
I was thinking about using custom control that will Inherit from ComboBox
and use DependencyProperty.RegisterAttached
for the location of the Separator
(s)
but couldn't find a way to do so
PS
i prefer not use any code behind and not use <Setter Property="Template">
because i have base style and template that a lot of ComboBox
s in my program user
As you are using databinding, the items are grouped, so I would using grouping.
See this answer: Grouping items in a ComboBox (solved)
If you do not want to use grouping, then you could use this method: Insert ComboBox Item Separator Which is Filled Through Data Binding
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.