© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
11 replies
Mek

✅ Not Quite Understanding Model Usage

public class UserModel
{
  public int Id {get; set;}
  public string FirstName {get;set;}
  public string LastName {get;set;}
  public string Email {get;set;}
  public string Username {get;set;}
  public string Password {get;set;}
  public int TosAgree {get;set;}
  public UserCustomSettingsModel CustomSettings {get;set;}
}

public UserCustomSettingsModel
{
  public UserStylesModel UserStyles {get;set;}
  public UserSettingsModel UserSettings {get;set;}
}

public UserSettingsModel { public int UseOnlineStorage {get;set;} }

public UserStylesModel
{
  public string FontSize {get;set;}
  public string FontStyle {get;set;}
  public string FontColor {get;set;}
  public string BackgroundColor {get;set;}
  public string BorderColor {get;set;}
}
public class UserModel
{
  public int Id {get; set;}
  public string FirstName {get;set;}
  public string LastName {get;set;}
  public string Email {get;set;}
  public string Username {get;set;}
  public string Password {get;set;}
  public int TosAgree {get;set;}
  public UserCustomSettingsModel CustomSettings {get;set;}
}

public UserCustomSettingsModel
{
  public UserStylesModel UserStyles {get;set;}
  public UserSettingsModel UserSettings {get;set;}
}

public UserSettingsModel { public int UseOnlineStorage {get;set;} }

public UserStylesModel
{
  public string FontSize {get;set;}
  public string FontStyle {get;set;}
  public string FontColor {get;set;}
  public string BackgroundColor {get;set;}
  public string BorderColor {get;set;}
}
public partial class TosViewModel : ViewModelBase
{
  public void SetupUI()
  {
    FontSize = User.CustomSettings.UserStyles.FontSize;
    FontStyle = User.CustomSettings.UserStyles.FontStyle;
    Foreground = User.CustomSettings.UserStyles.FontColor;
    Background = User.CustomSettings.UserStyles.BackgroundColor;
    Border = User.CustomSettings.UserStyles.BorderColor;
    Border2 = "#CDCDCD";
  }
}
public partial class TosViewModel : ViewModelBase
{
  public void SetupUI()
  {
    FontSize = User.CustomSettings.UserStyles.FontSize;
    FontStyle = User.CustomSettings.UserStyles.FontStyle;
    Foreground = User.CustomSettings.UserStyles.FontColor;
    Background = User.CustomSettings.UserStyles.BackgroundColor;
    Border = User.CustomSettings.UserStyles.BorderColor;
    Border2 = "#CDCDCD";
  }
}
In my view model, I am trying to use the styles that are attached to the user model, however, I keep getting the error on
UserCustomSettings.UserStyles.FontSize
UserCustomSettings.UserStyles.FontSize
saying
'Object reference not set to an instance of an object'
'Object reference not set to an instance of an object'
. Like I understand that means I have to do
UserStylesModel userStyles = new()
UserStylesModel userStyles = new()
but I don't want to overwrite what's pulled from the database so how do I fix this? Thanks.
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

❔ Understanding the model-view-controller
C#CC# / help
3y ago
❔ Need help understanding Model Binding better
C#CC# / help
3y ago
Not understanding this lesson
C#CC# / help
12mo ago
✅ Not understanding Microsoft Tutorial
C#CC# / help
2y ago