© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
6 replies
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

deserialize non-nullable
C#CC# / help
2y ago
❔ Non-nullable field 'rating' must contain a non-null value when exiting constructor
C#CC# / help
4y ago
✅ Non-nullable property netstandard2.0
C#CC# / help
13mo ago
✅ Help with non-nullable field must contain a non-null value when exiting constructor.
C#CC# / help
3y ago