I have an application where you can select between different objects in a ListBox. When you select an object, it changes the viewmodel for a control. The control utlizes the Timeline Control from CodePlex, and because of this, I have the StartDate and EndDate for the timeline data bound to ViewModel. When the ViewModel is changed out, I sometimes get an error:
ArgumentOutOfRangeException: MaxDateTime cannot be less then MinDateTime
This only occurs when I go from a later date to an earlier date. I am pretty sure that is due to the way the Properties are automatically updated to the view. This is the relevant XAML.
MaxDateTime="{Binding Path=RecordingEnd}"
MinDateTime="{Binding Path=RecordingStart}"
CurrentDateTime="{Binding Path=CurrentDateTime, Mode=TwoWay}"
The ViewModel has this:
private int myObjectIndex;
public int MyObjectIndex
{
get { return myObjectIndex; }
set { myObjectIndex = value; OnPropertyChanged("MyObjectIndex"); MyObject = MyObjects[myObjectIndex]; }
}
private MyObjectViewModel myObject=new MyObjectViewModel();
public MyObjectViewModel MyObject {
get { return myObject; }
set
{
myObject= value;
OnPropertyChanged("MyObject");
}
}
Is there a way around this problem? Is there a way to tell WPF which order the parameters within an object should be updated?
Update: I ended up using a variation of @colinsmith's response:
public MyObjectViewModel MyObject {
get { return myObject; }
set
{
myObject= new MyObjectViewModel();
OnPropertyChanged("MyObject");
myObject= value;
OnPropertyChanged("MyObject");
}
}
Could you try this:
public MyObjectViewModel MyObject {
get { return myObject; }
set
{
myObject=null;
OnPropertyChanged("MyObject");
myObject= value;
OnPropertyChanged("MyObject");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With