我有一个列表框,里面有各种堆栈面板。 一个是用文本块和组合框形成的:
e
然后,在后面的代码中我设置了各种维度
<ListBox x:Name="lb1Tab3" Visibility="Visible" HorizontalContentAlignment="Stretch" Height="1500" VerticalAlignment="Stretch" VerticalContentAlignment="Center" FontSize="{StaticResource BUTTON_FONTSIZE}" Background="Transparent" BorderBrush="{x:Null}" >
<StackPanel Name="sp1_lb1Tab3" Background="Red" Orientation="Horizontal" VerticalAlignment="Center" Margin="0" >
<TextBlock x:Name="lbLanguage" Margin="20" HorizontalAlignment="Left" VerticalAlignment="Center" Text="Language"/>
<ComboBox x:Name="cmbLanguages" Margin="20" HorizontalAlignment="Left" VerticalAlignment="Center" Width="246" Height="35" DropDownClosed="ComboBox_DropDownClosed"/>
</StackPanel>
我希望它们是垂直居中的,但效果是:
答案 0 :(得分:1)
int marginText = 40;
lbLanguage.Height = easyRunData.FontSize + marginText;
由于MarginText为40,因此它将lbLanguage大小增加到大于组合框,并使其对齐得更高。可能尝试较少的数字。比如int marginText = 25;