0

for testing purposes i created a simple object-list. I display the data in a datagrid with this code:

<DataGrid x:Name="dataGrid1" 
          IsReadOnly="True" 
          HorizontalAlignment="Left" 
          Margin="50,30,0,0" 
          VerticalAlignment="Top" 
          Height="251" 
          Width="544" 
          AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Name" Binding="{Binding Birthday}" />
    </DataGrid.Columns>
</DataGrid>

This works great, but my birthday is a datatype DateTime so how can i modify this bound data? I just want to show the DateTime.toShortDateString() value.

Felix D.
  • 4,811
  • 8
  • 38
  • 72
Mathis Hüttl
  • 281
  • 4
  • 18
  • Possible duplicate of [WPF Binding StringFormat Short Date String](http://stackoverflow.com/questions/5046429/wpf-binding-stringformat-short-date-string) – Felix D. Dec 16 '16 at 09:03

1 Answers1

1

You need to use the StringFormat in your binding.

<TextBlock Text="{Binding Date, StringFormat='{}{0:dd.MM.yyyy}'}" /> // 16.12.2016

See this answer.

Community
  • 1
  • 1
Felix D.
  • 4,811
  • 8
  • 38
  • 72