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:
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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With