© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
15 replies
mario12136

❔ Settings model as a singleton in WPF

I have been using
Properties.Settings.Default
Properties.Settings.Default
for my application which automatically saves a config file in the AppData\Local folder and I have been wanting to create a settings model to have more control over the file location and other things. Since my requirements were that there be a single instance that is accessible all throughout my app, I have found that this is called the Singleton pattern. The class I will create will read from and write as Json.

My question is is this common and a correct use of the Singleton pattern? Is there something that I need to consider further before creating my
Settings
Settings
class.

Also any relevant resources/guides would be appreciated.

What I have
    internal sealed class SettingsModel
    {
        private static SettingsModel _instance;

        public static SettingsModel Instance
        {
            get
            {
                _instance ??= new SettingsModel();
                return _instance;
            }
        }

        private SettingsModel()
        {
        }

        [JsonPropertyName("FontSize")]
        public int FontSize { get; set; }

        [JsonPropertyName("FontFamily")]
        public FontFamily FontFamily { get; set; }

        }
    internal sealed class SettingsModel
    {
        private static SettingsModel _instance;

        public static SettingsModel Instance
        {
            get
            {
                _instance ??= new SettingsModel();
                return _instance;
            }
        }

        private SettingsModel()
        {
        }

        [JsonPropertyName("FontSize")]
        public int FontSize { get; set; }

        [JsonPropertyName("FontFamily")]
        public FontFamily FontFamily { get; set; }

        }
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

✅ WPF Store Singleton Action PropertyChanged optimization
C#CC# / help
4y ago
✅ WPF UI (lepoco/wpfui) Questions
C#CC# / help
2y ago
❔ ✅ Register instance of List as singleton
C#CC# / help
3y ago
Play a Sound file as a URL Link in WPF
C#CC# / help
2y ago