【发布时间】:2015-09-10 09:18:09
【问题描述】:
我使用 WPF 4.5、Caliburn Micro 2、VS2013。我使用 TextBlock 作为 ComboBox 中的项目。
ComboBox 的高度为 80。
TextBlock 的高度为 50。
TextBlock 内文字的字体大小是标准的。
我的以下示例 xaml 代码有效,但它显示的文本未在 TextBlock 中垂直居中。 如何使文本垂直居中,无论是否将 TextBlock 的高度更改为 Auto? 提前致谢。
<ComboBox Width="150"
Height="80"
VerticalContentAlignment="Center"
ItemsSource="{Binding Path=Locations}"
SelectedIndex="0"
SelectedItem="{Binding Path=SelectedLocation,
Mode=OneWayToSource}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Height="50"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Background="Aquamarine"
Text="{Binding Path=Address}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
这是截图:
【问题讨论】:
标签: wpf combobox vertical-alignment textblock