Hi,
I have multiple viewModels in my application and am binding/used them in ViewModelLocator mvvm light. I have done button on one of my DailyActivities.xaml page. but when i clicked on it,it gives me error in ViewModelLocator like "Object reference not set to an instance of an object". and control comes to this line :
public static void ClearActivities() { _activities.Cleanup(); //Error here _activities = null; }
here is the code for DailyActivitiesViewModel in ViewModelLocator:
private static ActivitiesViewModel _activities;
public static ActivitiesViewModel ActivitiesStatic
{
get
{
if (_activities == null)
{
CreateActivities();
}
return _activities;
}
}
/// <summary>
/// Gets the ViewModelPropertyName property.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1822:MarkMembersAsStatic",
Justification = "This non-static member is needed for data binding purposes.")]
public ActivitiesViewModel Activities
{
get
{
return ActivitiesStatic;
}
}
/// <summary>
/// Provides a deterministic way to delete the ViewModelPropertyName property.
/// </summary>
public static void ClearActivities()
{
_activities.Cleanup(); --Error here
_activities = null;
}
/// <summary>
/// Provides a deterministic way to create the ViewModelPropertyName property.
/// </summary>
public static void CreateActivities()
{
if (_activities == null)
{
_activities = new ActivitiesViewModel();
}
}
Kindly Suggest?
Thanks