-2

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

P.S

i prefer not use any code behind and not use <Setter Property="Template"> because i have base style and template that a lot of ComboBoxs in my program user

styx
  • 1,852
  • 1
  • 11
  • 22
  • Have you considered binding itemssource to List and data templating viewmodels into separators? That's how I do separators usually. – Andy Jan 12 '23 at 09:12

1 Answers1

0

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

  • how would grouping would help me? i have seen the 2nd solution. TBH it looks bad and it dosent help my problem – styx Jan 12 '23 at 06:04