My XMAL as below
<xctk:CheckListBox x:Name="SiteCheckList" Margin="0,0,512,0" Height="100" Width="150" ItemsSource="{Binding SiteList}" DisplayMemberPath="SiteName" CheckedMemberPath="IsChecked" Command="{Binding Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"> </xctk:CheckListBox>
Model
private string _SiteName;
public string SiteName { get { return _SiteName; } set { _SiteName = value; } }
private bool _IsChecked;
public bool IsChecked { get { return _IsChecked; } set { _IsChecked = value; } }
ViewModel
private ObservableCollection<HistoricalDataModel> _SiteList;
public ObservableCollection<HistoricalDataModel> SiteList { get { return _SiteList; } set { _SiteList = value; } }
public bool IsChecked { get { return _IsChecked; } set { if (_IsChecked !=value) { _IsChecked = value; } OnPropertyChanged(nameof(IsChecked)); } }
public HistoricalDataViewModel() { SiteList = new ObservableCollection<HistoricalDataModel>(); PoppulateSiteNames(); }
private void PoppulateSiteNames() { Dictionary<string, string> keyValuePairs = new Dictionary<string, string>(); keyValuePairs = Files.ReadIni_KeyValue(Vars.MSSQL_Section); foreach (string Key in keyValuePairs.Keys) { keyValuePairs.TryGetValue(Key, out string LogTable); SiteList.Add(new HistoricalDataModel() { SiteName = LogTable }); }
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string PropertyName) { if (PropertyChanged !=null) { PropertyChanged(this, new PropertyChangedEventArgs(PropertyName)); } }