Search code examples
c#wpfvisual-studio-2010ribbon

WPF RibbonComboBox scroll bar / limit number of items


I'm having problems with the RibbonComboBox in WPF. I have a list with a lot of items I want to add. There are too many items to fit into the window and so you can't see every item. This wouldn't be too bad, but the problem is that there is no scroll bar. I can scroll with the keyboard and the cursor then goes missing until I reach the end of the list and then I'm back on the top of the list. Is there a way to a) have a scrollbar b) limit the number of elements that are shown when the dropdown button is clicked (I know it works for the regular combobox)?

I'm using Visual Studio 2010.

Best wishes C


Solution

  • Your requirements can be achieved, but unfortunately, it will be a very painful procedure. The reason why the RibbonComboBox does not have a ScrollBar is because whoever developed it did a really poor job. Apparently, the default ControlTemplate uses a StackPanel internally, which as we all know is totally useless for these kinds of sizing issues.

    As more items are added, the StackPanel just lets the ItemsPresenter grow infinitely. You can find a bit of a description of this in the RibbonComboBox does not display a scroll bar when appropriate page on CodePlex.

    Therefore the fix is for you to declare a new ControlTemplate based on the default one and to replace this StackPanel with a Grid, or DockPanel as the linked page advises (although I personally think that a DockPanel might be a bit expensive for this task).

    So how do you get the default ControlTemplate to base yours upon? Well, Microsoft have also made that more difficult by not providing it along with all of there other controls in the Control Styles and Templates pages on MSDN. Instead, you can use Blend to find it and you can get help with that task by reading the Blend tip: finding default styles using “Edit a Copy” page on Jeff Wilcox's website.

    Good luck.