WPF DatePicker to show the time as well as the date WPF DatePicker to show the time as well as the date wpf wpf

WPF DatePicker to show the time as well as the date


In addition to, without using other components, if you just want to display a date in the format that you want to edit it, you can do this:

    <DataGridTemplateColumn.CellTemplate>        <DataTemplate>            <TextBlock  Text="{Binding Path=Date,StringFormat={}{0:dd/MM/yyyy}}"  VerticalAlignment="Center" HorizontalAlignment="Left">            </TextBlock>        </DataTemplate>    </DataGridTemplateColumn.CellTemplate>


You could do something like this:

            <DataGridTemplateColumn Header="YourDate">                <DataGridTemplateColumn.CellEditingTemplate>                    <DataTemplate>                        <StackPanel Orientation="Horizontal">                            <DatePicker SelectedDate="{Binding YourDate, UpdateSourceTrigger=PropertyChanged}" />                            <TextBox Margin="2 0 0 0" Text="{Binding YourDate, UpdateSourceTrigger=PropertyChanged, StringFormat='t'}" />                        </StackPanel>                    </DataTemplate>                </DataGridTemplateColumn.CellEditingTemplate>                <DataGridTemplateColumn.CellTemplate>                    <DataTemplate>                        <TextBlock Text="{Binding YourDate}" />                    </DataTemplate>                </DataGridTemplateColumn.CellTemplate>            </DataGridTemplateColumn>

This will show an DatePicker next to an TextBox wich are bound to the same property. The TextBox got an StringFormat to only show the date.

UpdateSourceTrigger is set to PropertyChanged, so the user can't do an conflict.