Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I center a ComboBox's content vertically?

Tags:

combobox

wpf

xaml

For example, notice how the text isn't quite in the vertical center of the ComboBox.

enter image description here

Here's my XAML:

<Window x:Class="_24HoursBook.MainWindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         Title="MainWindow" Height="450" Width="350" MinHeight="450" MinWidth="350">       <Grid ShowGridLines="True">         <Grid.RowDefinitions>             <RowDefinition Height="0.15*" />             <RowDefinition />         </Grid.RowDefinitions>         <Image Grid.Row="0" Stretch="Fill" Source="Image/topBarBg.png" />         <StackPanel Orientation="Horizontal" Grid.Row="0">                         <TextBlock Text="Platform"                         Foreground="White"                         FontFamily="Georgia"                        FontSize="15"                         Margin="10"                        HorizontalAlignment="Center"                        VerticalAlignment="Center"/>             <ComboBox x:Name="cmbPlatform"                        Margin="10"                       FontFamily="Georgia"                       FontSize="15"                       MinHeight="30"                       MinWidth="140"                       VerticalAlignment="Center">                 <ComboBoxItem>All Platforms</ComboBoxItem>                 <ComboBoxItem>Playstation 3</ComboBoxItem>                 <ComboBoxItem>XBox 360</ComboBoxItem>                 <ComboBoxItem>Wii</ComboBoxItem>                 <ComboBoxItem>PSP</ComboBoxItem>                 <ComboBoxItem>DS</ComboBoxItem>             </ComboBox>                     </StackPanel>         <Image Grid.Row="0" Source="Image/about.png"                 Height="16" HorizontalAlignment="Right"                VerticalAlignment="Center"                Margin="0 0 10 0"    />          <ListView Grid.Row="1" Background="#343434">          </ListView>     </Grid> </Window> 
like image 937
Only Bolivian Here Avatar asked May 14 '11 21:05

Only Bolivian Here


1 Answers

Add VerticalContentAlignment="Center" to your combobox.

like image 91
Alex Aza Avatar answered Sep 25 '22 05:09

Alex Aza