6

I am using a DatePicker in my app defined as such:

<DatePicker Width="200"
            Margin="20, 20, 20, 0"
            SelectedDate="{Binding PeriodEndDate, Mode=TwoWay}" />

Here is how the date picker is displayed:

enter image description here

How can I get the date (4/22/2015) to center vertically in the textbox (the dotted line around the date is the actual textbox boundary)?

I have tried setting both VerticalContentAlignment and VerticalAlignment to Center but this doesn't affect the date centering.

If I dig into the date picker using Snoops I can see an element called PART_TextBox within the DatePicker. If I change this PART_TextBox VerticalContentAlignment to Center, the text will be centered (is set to Stretch by default). However, I do not know how to access this subcomponent to change it's VerticalContentAlignment

Claudio P
  • 2,133
  • 3
  • 25
  • 45
BrianKE
  • 4,035
  • 13
  • 65
  • 115
  • [http://stackoverflow.com/questions/1530640/centering-datepicker-control](http://stackoverflow.com/questions/1530640/centering-datepicker-control) This can be handled by defining a style. – EMAW2008 Dec 11 '15 at 16:08

1 Answers1

2

I would guess this is a product of your font size. Try.

<DatePicker Width="200"
            FontSize="8"
            Margin="20, 20, 20, 0"
            SelectedDate="{Binding PeriodEndDate, Mode=TwoWay}" >

    <DatePicker.Resources>
        <Style TargetType="DatePickerTextBox">
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>
    </DatePicker.Resources>

</DatePicker>
Andy Reed
  • 333
  • 2
  • 11