Reputation: 599
I have a sample project with an DataGrid
that have a DataGridTemplateColumn
that have as DataTemplate
a CalendarDatePicker
,
If I try to add a row to the binded ItemSource
, the date is always 01/01/1920.
I have check inside the ItemSource
, and the value is correct (es. DateTime.Now
).
I have attached the project.
How can I solve this issue?
Upvotes: 0
Views: 51
Reputation: 32775
UWP DataGrid Datetime binding issue
That's interesting, I checked your code, I found DataLavoro
type is DateTime
, but Date
DependencyProperty
allowed type is DateTimeOffset
. I edit your code like the following and CalendarDatePicker works.
Xaml
private void AggiungiRiga()
{
DateTimeOffset adesso = DateTimeOffset.Now;
ListaOrari.Add(new Orario
{
Id = 5,
DataLavoro = adesso,
Inizio = new TimeSpan(adesso.Hour, adesso.Minute, 0)
});
}
Model
public DateTimeOffset DataLavoro
{
get { return _dataLavoro; }
set { _dataLavoro = value; }
}
private DateTimeOffset _dataLavoro;
Upvotes: 1