-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

1
  • Have you considered binding itemssource to List<object> and data templating viewmodels into separators? That's how I do separators usually. Commented Jan 12, 2023 at 9:12

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

how would grouping would help me? i have seen the 2nd solution. TBH it looks bad and it dosent help my problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.