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. "
2 Replies
object
💀
And, yeah, the field can end up having no value
So either give it a value in the constructor, or give it the value of null!
to suppress the error
Maybe making the property required
could also solve itsoooo
in my main window i had
and i needed it to say MainViewModel not home..