In my WPF application on .NET 4.0, I'm using two DatePicker
s and two TextBlock
s in a horizontal StackPanel
, and it looks like this:
In the left DatePicker
, I experimented with a higher font size. Apart from that, there are no special settings or styles.
The buttons are aligned to the TextBlock
s, but the text in the DatePicker
is not.
Any idea how to change the alignment of the date text?
EDIT: Here's my XAML:
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Right" VerticalAlignment="Bottom"
>
<TextBlock Text="from " />
<DatePicker SelectedDate="{Binding FromDate, Mode=TwoWay}" FontSize="14" />
<TextBlock Text=" until " />
<DatePicker SelectedDate="{Binding ToDate, Mode=TwoWay}" />
</StackPanel>
Thanks Jorge, it was a Button
style in the App.xaml:
<Style TargetType="{x:Type Button}">
<Setter Property="Margin" Value="0 5 10 5" />
</Style>
This style applied to the button inside of the DatePicker
as well.
Assuming you are working with textblocks then you could try something like this.
<StackPanel Orientation="Horizontal" Height="40" Margin="10">
<Border Background="Transparent" BorderBrush="#FF2A2A89" BorderThickness="2">
<TextBlock Width="150" Text="Testing" TextAlignment="Center"
VerticalAlignment="Center" />
</Border>
<DatePicker VerticalContentAlignment="Center" Name="datepicker" />
</StackPanel>
The content it's really just for demonstrating. You should get something like this:
However If you are just showing the date why don't you use the datepicker with the default settings? It shows the selected date by default.
Another way to do it, you could use textbox instead of textblocks and set IsReadOnly as true. I'm assuming you are using textblocks so they are not editable. Using textboxes you can set VerticalContentAlignment="Center" and that's it.
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