Mathis Hüttl
Mathis Hüttl

Reputation: 301

WPF DataGrid modify bound data

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.

Upvotes: 0

Views: 53

Answers (1)

Felix D.
Felix D.

Reputation: 5083

You need to use the StringFormat in your binding.

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

See this answer.

Upvotes: 1

Related Questions