Search code examples
wpfvertical-alignmentribbon-control

Vertically center RibbonComboBox in RibbonGroup (in WPF)


I would like know whether there is a possibility to vertically center a RibbonComboBox in a RibbonGroup without setting a margin. I tried to use VerticalAlignment and VerticalContentAlignment, but unfortunately this did not work.

This is how it looks right now:

Right now

This is how it should look like (please without using margin-settings):

required

This is my code at the moment:

<RibbonTab Name="RibbonTab_Test" Header="Test">
   <RibbonGroup Name="RibbonGroup_Test" Header="New Test">
       <RibbonComboBox Name="RibbonComboBox_Test" IsEditable="False" SmallImageSource="img/verschreibungspflichtige-pillendose-16.png">
           <RibbonGallery SelectedValue="This Test-Text is to long" SelectedValuePath="Content" MaxColumnCount="1">
               <RibbonGalleryCategory>
                  <RibbonGalleryItem Content="This Test-Text is to long"/>
                  <RibbonGalleryItem Content="Test 1"/>
                  <RibbonGalleryItem Content="Test 2"/>
               </RibbonGalleryCategory>
            </RibbonGallery>
        </RibbonComboBox>
    </RibbonGroup>
</RibbonTab>

Thank you for your help!


Solution

  • One way to achieve this is by adding a grid with a very big height and setting vertical alignment to center:

    <RibbonGroup Name="RibbonGroup_Test" Header="New Test">
        <Grid VerticalAlignment="Center" MinHeight="120">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
            <RibbonComboBox Name="RibbonComboBox_Test" IsEditable="False" VerticalAlignment="Center" SmallImageSource="img/verschreibungspflichtige-pillendose-16.png">
                <RibbonGallery SelectedValue="This Test-Text is to long" SelectedValuePath="Content" MaxColumnCount="1" >
                    <RibbonGalleryCategory>
                        <RibbonGalleryItem Content="This Test-Text is to long"/>
                        <RibbonGalleryItem Content="Test 1"/>
                        <RibbonGalleryItem Content="Test 2"/>
                    </RibbonGalleryCategory>
                </RibbonGallery>
            </RibbonComboBox>
        </Grid>
    </RibbonGroup>
    

    Vertical aligned ribbon