I am using C# WPF XAML to create an application. One form has a date picker. I want to center align the text and the selected date inside the textbox of date picker. Below is the code I am using but it is not working
<DatePicker x:Name="DatePicker1" Margin="0,128,0,0" SelectedDateFormat="Long" HorizontalAlignment="Center" VerticalAlignment="Top" Height="30" Width="250" FontFamily="Calibri" FontSize="16" FontWeight="Regular" TabIndex="1" BorderBrush="#162D2D" Foreground="#D9D9D9" Padding="0,0,0,0">
<DatePicker.Resources>
<Style TargetType="{x:Type DatePickerTextBox}">
<Setter Property="Text" Value="Select Buy Date"/>
<Setter Property="Padding" Value="0,2,0,0"/>
<Setter Property="Background" Value="#FF162D2D"/>
<Setter Property="Height" Value="28"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
</DatePicker.Resources>
</DatePicker>
1
Text Alignment Property suggested by Sinus32 worked. Below is the updated code
<DatePicker x:Name="DatePicker1" Margin="0,128,0,0" SelectedDateFormat="Long" HorizontalAlignment="Center" VerticalAlignment="Top" Height="30" Width="250" FontFamily="Calibri" FontSize="16" FontWeight="Regular" TabIndex="1" BorderBrush="#162D2D" Foreground="#D9D9D9" Padding="0,0,0,0">
<DatePicker.Resources>
<Style TargetType="{x:Type DatePickerTextBox}">
<Setter Property="Text" Value="Select Buy Date"/>
<Setter Property="Padding" Value="0,2,0,0"/>
<Setter Property="Background" Value="#FF162D2D"/>
<Setter Property="Height" Value="28"/>
<Setter Property="TextAlignment" Value="Center"/>
</Style>
</DatePicker.Resources>