I'm building a WPF application that uses simple MVVM architecture and EF.
I'm seeing a weird issue where if I try to set a datetime property, I get a System.StackOverflowException
. If I don't set the datetime property, I don't get the exception.
Binding:
<DatePicker Style="{StaticResource Dp}"
Grid.Column="1"
SelectedDate="{Binding Date, UpdateSourceTrigger=PropertyChanged}" />
Public property:
public DateTime Date
{
get
{
return _criticalDate.Date;
}
set
{
if (_criticalDate != null && value != null && _criticalDate.Date == value)
return;
_criticalDate.Date = value;
OnPropertyChanged("Date");
}
}
Trying to step through it with a debugger doesn't seem to work. I've looked at everything trying to see what is going on... any hints on what might be causing this?
This is the definition for the CriticalDate
class,
public partial class CriticalDate
{
public int ID { get; set; }
public System.DateTime Date { get; set; }
public string CriticalReason { get; set; }
public int FileID { get; set; }
}
The _criticalDate
field is a private instance of the CriticalDate
class. CriticalDate
is a class created by EF from my DB schema. It isn't itself a DateTime
.
FINAL UPDATE
I still don't know what was wrong... I tore the offending section out (including the binding) and rewrote it from scratch. No clue what I did differently, but it works now. I think it was something to do with how an itemscontrol was set up... if I had more time (stupid deadlines) I'd go back to see what it was, but for now it's a mystery.
Thanks for sharing in my confusion, if only ever so briefly.