在RibbonGroup中垂直居中RibbonComboBox(在WPF中)

时间:2018-06-15 12:23:02

标签: wpf vertical-alignment ribbon-control

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

这就是现在的样子:

Right now

它应该是这样的(请不要使用保证金设置):

required

这是我目前的代码:

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

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

实现这一目标的一种方法是添加一个非常大的网格,并将垂直对齐设置为中心:

<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