首页 > 解决方案 > RibbonGroup 中的 RibbonComboBox 垂直居中(在 WPF 中)

问题描述

我想知道是否有可能在 RibbonGroup 中将 RibbonComboBox 垂直居中而不设置边距。我尝试使用 VerticalAlignment 和 VerticalContentAlignment,但不幸的是这不起作用。

这是它现在的样子:

马上

这就是它的样子(请不要使用边距设置):

必需的

这是我目前的代码:

<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>

谢谢您的帮助!

标签: wpfvertical-alignmentribbon-control

解决方案


实现此目的的一种方法是添加一个高度非常大的网格并将垂直对齐设置为居中:

<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>

垂直对齐的色带


推荐阅读