堆栈面板未居中对齐
stackpanel not center-aligning
我有一个列表框,里面有各种堆栈面板。
一个由文本块和组合框组成:
<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>
然后,在后面的代码中我设置了各种维度
int marginStackPanel = 40 * 2;
int marginText = 40;
int marginComboBox = 20;
/*-------------------*/
sp1_lb1Tab3.Height = easyRunData.FontSize + marginStackPanel;
sp1_lb1Tab3.VerticalAlignment = VerticalAlignment.Center;
lbLanguage.Height = easyRunData.FontSize + marginText;
lbLanguage.FontSize = easyRunData.FontSize;
cmbLanguages.Height = easyRunData.FontSize +marginComboBox ;
cmbLanguages.FontSize = easyRunData.FontSize;
我希望它们垂直居中,但效果是:
感谢您的帮助
int marginText = 40;
lbLanguage.Height = easyRunData.FontSize + marginText;
由于 MarginText 为 40,因此它增加了 lbLanguage 的大小,使其比组合框更大,并将其对齐得更高。可能尝试较小的数字。喜欢 int marginText = 25;
我有一个列表框,里面有各种堆栈面板。 一个由文本块和组合框组成:
<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>
然后,在后面的代码中我设置了各种维度
int marginStackPanel = 40 * 2;
int marginText = 40;
int marginComboBox = 20;
/*-------------------*/
sp1_lb1Tab3.Height = easyRunData.FontSize + marginStackPanel;
sp1_lb1Tab3.VerticalAlignment = VerticalAlignment.Center;
lbLanguage.Height = easyRunData.FontSize + marginText;
lbLanguage.FontSize = easyRunData.FontSize;
cmbLanguages.Height = easyRunData.FontSize +marginComboBox ;
cmbLanguages.FontSize = easyRunData.FontSize;
我希望它们垂直居中,但效果是:
int marginText = 40;
lbLanguage.Height = easyRunData.FontSize + marginText;
由于 MarginText 为 40,因此它增加了 lbLanguage 的大小,使其比组合框更大,并将其对齐得更高。可能尝试较小的数字。喜欢 int marginText = 25;