Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8614319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:05:40+00:00 2026-06-12T05:05:40+00:00

I’m attempting to build a CheckedListBox in WPF and bind it to the user

  • 0

I’m attempting to build a CheckedListBox in WPF and bind it to the user settings so that it is constructed once only and then updates the settings automatically in XAML using ListBox ItemsSource="{Binding Source={x:Static local:Settings.Default}, Path=Customers, Mode=TwoWay}

I can see the checkboxes but they don’t show the Customer name and don’t retain their values in settings. Is anyone able to spot why?

I think I may need to cast from the settings to the current Customers ObservableCollection but can’t get this working?

Customers = Properties.Settings.Default.Customers.Cast;

TestSettings.xaml

<Window x:Class="WpfApplication1.TestSettings"
        xmlns:local="clr-namespace:WpfApplication1.Properties"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="TestSettings" Height="300" Width="300">
    <Grid>
    <ListBox ScrollViewer.VerticalScrollBarVisibility="Auto" ItemsSource="{Binding Source={x:Static local:Settings.Default}, Path=Customers, Mode=TwoWay}" Margin="12,22,12,79">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <CheckBox IsChecked="{Binding IsChecked}" Content="{Binding Path=Item.CustomerName}" />
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    </Grid>
</Window>

TestSettings.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for TestSettings.xaml
    /// </summary>
    public partial class TestSettings : Window
    {

        public ObservableCollection<CheckedListItem<Customer>> Customers { get; set; }

        public class Customer
        {
            public string CustomerName { get; set; }
        }

        public TestSettings()
        {
            InitializeComponent();

            if (Properties.Settings.Default.Customers == null)
            {
                Properties.Settings.Default.Customers = new ObservableCollection<Customer> 
                { 
                        new Customer() { CustomerName = "Kelly Smith" },
                        new Customer() { CustomerName = "Joe Brown" },
                        new Customer() { CustomerName = "Herb Dean" }

                    //Customers.Add(new CheckedListItem<Customer>(new Customer(){CustomerName="Kelly Smith"}));
                    //Customers.Add(new CheckedListItem<Customer>(new Customer(){CustomerName="Joe Brown"}));
                    //Customers.Add(new CheckedListItem<Customer>(new Customer(){CustomerName="Herb Dean"}));

                };
                Properties.Settings.Default.Save();
            }
            else
            {
               // Customers = (ObservableCollection<Customer>)Properties.Settings.Default.Customers;
            }
        }

        public class CheckedListItem<T> : INotifyPropertyChanged
        {
            public event PropertyChangedEventHandler PropertyChanged;

            private bool isChecked;
            private T item;

            public CheckedListItem()
            { }

            public CheckedListItem(T item, bool isChecked = false)
            {
                this.item = item;
                this.isChecked = isChecked;
            }

            public T Item
            {
                get { return item; }
                set
                {
                    item = value;
                    if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Item"));
                }
            }


            public bool IsChecked
            {
                get { return isChecked; }
                set
                {
                    isChecked = value;
                    if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("IsChecked"));
                }
            }
        }

        private void Window_Closing(object sender, CancelEventArgs e)
        {
            Properties.Settings.Default.Save();
        }
    }
}

Settings.Designer.cs

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.269
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System.Collections.ObjectModel;
namespace WpfApplication1.Properties
{


    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
    {

        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

        public static Settings Default
        {
            get
            {
                return defaultInstance;
            }

        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public ObservableCollection<WpfApplication1.TestSettings.Customer> Customers
        {
            get
            {
                return ((ObservableCollection<WpfApplication1.TestSettings.Customer>)(this["Customers"]));
            }
            set
            {
                this["Customers"] = value;
            }
        }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:05:41+00:00Added an answer on June 12, 2026 at 5:05 am

    OK – Sorted.

    There were 2 main problems

    1/ I was only adding CustomerName and not the CheckListItem so

    ObservableCollection<Customer> should be ObservableCollection<CheckedListItem<Customer>>

    2/ Same again adding the customers.

    new Customer() { CustomerName = "Kelly Smith" } should be new CheckedListItem<Customer>(new Customer() { CustomerName = "Kelly Smith" })

    So full working code is

    Settings.Designer.cs

    using System.Collections.ObjectModel;
    namespace WpfApplication1.Properties {
    
    
        [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
        internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
    
            private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
    
            public static Settings Default {
                get {
                    return defaultInstance;
                }
            }
    
            [global::System.Configuration.UserScopedSettingAttribute()]
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
            public ObservableCollection<WpfApplication1.TestSettings.CheckedListItem<WpfApplication1.TestSettings.Customer>> Customers
            {
                get
                {
                    return ((ObservableCollection<WpfApplication1.TestSettings.CheckedListItem<WpfApplication1.TestSettings.Customer>>)(this["Customers"]));
                }
                set
                {
                    this["Customers"] = value;
                }
            }
        }
    }
    

    TestSettings.xaml

    <Window x:Class="WpfApplication1.TestSettings"
            xmlns:local="clr-namespace:WpfApplication1.Properties"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="TestSettings" Height="300" Width="300" Closing="Window_Closing">
        <Grid>
            <ListBox ScrollViewer.VerticalScrollBarVisibility="Auto" ItemsSource="{Binding Source={x:Static local:Settings.Default}, Path=Customers, Mode=TwoWay}" Margin="12,22,12,79">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <CheckBox IsChecked="{Binding IsChecked}" Content="{Binding Path=Item.CustomerName}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </Window>
    

    TestSettings.xaml.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
    using System.ComponentModel;
    using System.Collections.ObjectModel;
    
    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for TestSettings.xaml
        /// </summary>
        public partial class TestSettings : Window
        {
    
            public ObservableCollection<CheckedListItem<Customer>> Customers
            {
                get;
                set;
            }
    
    
            public class Customer
            {
                public string CustomerName { get; set; }
            }
    
            public TestSettings()
            {
                InitializeComponent();
    
                if (Properties.Settings.Default.Customers == null)
                {
                    Properties.Settings.Default.Customers = new ObservableCollection<CheckedListItem<Customer>>
                    { 
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "Kelly Smith" }),
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "Joe Brown" }),
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "Herb Dean" }),
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "fg4" }),
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "fg5" }),
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "fg6" }),
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "fg7" }),
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "fg8" }),
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "fg9" }),
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "fg10" }),
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "fg11" }),
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "fg12" }),
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "fg13" }),
                            new CheckedListItem<Customer>(new Customer() { CustomerName = "fg14" })
    
                    };
                    Properties.Settings.Default.Save();
    
                }
                else
                {
                    //var a = Properties.Settings.Default.Customers;
                    //Customers = ObservableCollection<CheckedListItem<>>;
    
                }
            }
    
            public class CheckedListItem<T> : INotifyPropertyChanged
            {
                public event PropertyChangedEventHandler PropertyChanged;
    
                private bool isChecked;
                private T item;
    
                public CheckedListItem()
                { }
    
                public CheckedListItem(T item, bool isChecked = false)
                {
                    this.item = item;
                    this.isChecked = isChecked;
                }
    
                public T Item
                {
                    get { return item; }
                    set
                    {
                        item = value;
                        if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Item"));
                    }
                }
    
    
                public bool IsChecked
                {
                    get { return isChecked; }
                    set
                    {
                        isChecked = value;
                        if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("IsChecked"));
                    }
                }
            }
    
            private void Window_Closing(object sender, CancelEventArgs e)
            {
                Properties.Settings.Default.Save();
            }
        }
    }
    

    EDIT: It appears that this does work but as the Settings.Designer.cs has been amended the settings don’t persist between separate run-times as generic types cannot be stored in the settings. Rather than change Settings.Designer.cs I’ve ended up created and XML string which gets saved in the settings as a string and then build ObservableCollection> from the XML and vice versa.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.