I have a Datagrid which is bound to a Viewmodel. if I enter a date in a cell, something interrupts the user and messes up the input.
For example:
If I enter the DataGridTextColumn cell in a new empty Row it starts with 01.01.0001 (german date layout)
If I replace the string and start typing the first number and dot into the field it works as expected. But the next typed number will generate a whole date with setting the active year as the default value.
So I type 01.4 and then the Input in the cell will change to 01.04.2019, this is quite annoying and I have no clue how to change the behaviour. But I need to, because this makes inserting many rows with dates not ranging in the current year very unintuitive
The binding is an ObservableCollection with a custom class that has the OnPropertyChanged Technique implemented.
please help me find the correct place to change this behaviour
the observed behaviour is only with a DateTime bound to a datagridtextcolumn. there is no simple or intuitive solution to change this behaviour. My solution was to use a DataGridTemplateColumn, this control does not autocomplete your input in the most ridiculous und useless way imaginable.
Old Xaml:
<DataGridTextColumn Binding="{Binding Datum, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat=d}" Header="Aktionsdatum" />
New Xaml:
<DataGridTemplateColumn Header="Pick a Date">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Datum, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding Datum, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>