Hello!

At the time of studying Ribbon in WPF, I read in parallel MSDN, and pulled out an example of working with the Combobox, but I have scrolling from somewhere. Although the example from MSDN full copy * past.

https://msdn.microsoft.com/en-us/library/microsoft.windows.controls.ribbon.ribboncombobox(v=vs.100).aspx

What is the reason?

Expected result (from MSDN): MSDN example

As a result, I received: The result

XAML source code:

<r:RibbonWindow xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:r="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon" x:Class="RibbonExample.MainWindow" Title="MainWindow" Height="350" Width="525"> <Grid> <r:Ribbon> <r:RibbonTab Header="Главная"> <r:RibbonGroup Header="Пример"> <!--Начало пример MSDN--> <r:RibbonComboBox Label="1" SelectionBoxWidth="62" VerticalAlignment="Center" IsEditable="True"> <r:RibbonGallery SelectedValue="Green" SelectedValuePath="Content" MaxColumnCount="1"> <r:RibbonGalleryCategory> <r:RibbonGalleryItem Content="Green" Foreground="Green" /> <r:RibbonGalleryItem Content="Blue" Foreground="Blue" /> <r:RibbonGalleryItem Content="Orange" Foreground="Orange" /> </r:RibbonGalleryCategory> </r:RibbonGallery> </r:RibbonComboBox> <!--Конец примера--> </r:RibbonGroup> </r:RibbonTab> </r:Ribbon> </Grid> </r:RibbonWindow> 

More elements under the cursor are highlighted only where there is text, and not the full width of the drop-down list.

  • I tried to add: <r: RibbonGallery ScrollViewer.VerticalScrollBarVisibility = "Hidden"> But it didn't help - pincher1519
  • And add a link to MSDN for the completeness of the question :) - Denis Bubnov
  • @Denis Bubnov, added - pincher1519
  • Error in MSDN, now you know what they are there :) - vik_78

1 answer 1

Quite an interesting question about an example with MSDN, and this is what I got as a result of finding a solution to the question: if you jot down a typical example taken from MSDN - RibbonComboBox , you really get exactly what you have as a result - the scroll is displayed and the selected item is not highlighted under the cursor full width. These two problems I was able to solve as follows:


To remove Scroll from the drop-down list, simply add an item that turns off the scroll in the RibbonGallery properties:

 ScrollViewer.VerticalScrollBarVisibility="Disabled" 

I noticed that the width of the highlighting of the selected element is the maximum width of the text in the list. With the display of the selected item's backlight over the entire width of the aesthetically beautiful solution, alas, I did not find it, but I can offer two ways to solve this issue.

The easiest way is to set the width of one of the list items:

 <RibbonGalleryItem Content="Green" Foreground="Green" Width="76" /> 

Well, the second way, through setting the style for the type RibbonGalleryItem item like this:

 <RibbonGalleryCategory.Resources> <Style TargetType="RibbonGalleryItem"> <Setter Property="Width" Value="76"></Setter> </Style> </RibbonGalleryCategory.Resources> 

What code we see as a result of a RibbonComboBox :

 <RibbonComboBox Label="1" SelectionBoxWidth="62" VerticalAlignment="Center" IsEditable="True"> <RibbonGallery SelectedValue="Green" SelectedValuePath="Content" MaxColumnCount="1" ScrollViewer.VerticalScrollBarVisibility="Disabled"> <RibbonGalleryCategory> <RibbonGalleryCategory.Resources> <Style TargetType="RibbonGalleryItem"> <Setter Property="Width" Value="76"></Setter> </Style> </RibbonGalleryCategory.Resources> <RibbonGalleryItem Content="Green" Foreground="Green" /> <RibbonGalleryItem Content="Blue" Foreground="Blue" /> <RibbonGalleryItem Content="Orange" Foreground="Orange" /> </RibbonGalleryCategory> </RibbonGallery> </RibbonComboBox> 

Well, the corresponding image obtained on the form:

enter image description here

With the display of the highlight of the selected item on the entire width is not the best solution, I think it is possible to do better, but for a sketch and a temporary solution it is quite applicable, I think. As for MSDN , it’s not always what is true there, but it’s not often, especially since this page has been around for quite a few years, considering that this is for Visual Studio 2010, something may have changed since the page was published. , there were updates, changed default values.

  • one
    Cool! I reproduced the problem too, but my hands did not reach the solution. - VladD