C#C
C#2y ago
Killogee

Non-Nullable field (WPF)

Im currently using MVVM and trying to get the viewmodel to work

namespace WPFLearning.MVVM.ViewModel
{
class MainViewModel : ObservableObject
{

public HomeViewModel HomeVM { get; set; }

private object _currentView;

public object CurrentView
{
get { return _currentView; }
set
{
_currentView = value;
OnPropertyChanged();
}
}


public MainViewModel()
{
HomeVM = new HomeViewModel();
CurrentView = HomeVM;
}
}
}

But there is line under MainViewModel sayting that "Non-nullable field '_currentView' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. "
image.png
Was this page helpful?