From 657d74961f69b3098d2c8f68bae1f7d318ad7d36 Mon Sep 17 00:00:00 2001 From: Sreemon Premkumar M Date: Fri, 22 Aug 2025 17:26:13 +0530 Subject: [PATCH] ES-975464 - Resolve the ReadMe issue in this sample repository --- README.md | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3553928..05c679d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,114 @@ -# How to work with check boxes in bound mode in wpf treeview? -This repository describes how to work with check boxes in bound mode in wpf treeview +# How to work with check boxes in bound mode in WPF TreeView + +This repository describes how to work with check boxes in bound mode in [WPF TreeView](https://www.syncfusion.com/wpf-controls/treeview) (SfTreeView). + +When you are populating treeview nodes from [ItemsSource](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeView.SfTreeView.html#Syncfusion_UI_Xaml_TreeView_SfTreeView_ItemsSource), then you can get or set the checked items by using [CheckedItems](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeView.SfTreeView.html#Syncfusion_UI_Xaml_TreeView_SfTreeView_CheckedItems) property. + +SfTreeView supports to check multiple items through binding the `CheckedItems` property from view model with `ObservableCollection` type. + +#### XAML + +``` xml + + + + + + + + + + +``` + +#### C# + +``` csharp +public class ViewModel : NotificationObject +{ + public ObservableCollection Items { get; set; } + + private ObservableCollection checkedStates; + + public ObservableCollection CheckedStates + { + get { return checkedStates; } + set { checkedStates = value; } + } + + public ViewModel() + { + Items = new ObservableCollection(); + checkedStates = new ObservableCollection(); + + var country1 = new Model { State = "Australia" }; + var country2 = new Model { State = "Brazil" }; + var country3 = new Model { State = "China" }; + var country4 = new Model { State = "France" }; + + var aus_state1 = new Model { State = "New South Wales" }; + var aus_state2 = new Model { State = "Victoria" }; + var aus_state3 = new Model { State = "South Autralia" }; + var aus_state4 = new Model { State = "Western Australia" }; + + var brazil_state1 = new Model { State = "Parana" }; + var brazil_state2 = new Model { State = "Ceara" }; + var brazil_state3 = new Model { State = "Acre" }; + + var china_state1 = new Model { State = "Guangzhou" }; + var china_state2 = new Model { State = "Shanghai" }; + var china_state3 = new Model { State = "Beijing" }; + var china_state4 = new Model { State = "Shantou" }; + + var france_state1 = new Model { State = "Pays de la Loire" }; + var france_state2 = new Model { State = "Aquitaine" }; + var france_state3 = new Model { State = "Brittany" }; + var france_state4 = new Model { State = "Lorraine" }; + + country1.Models.Add(aus_state1); + country1.Models.Add(aus_state2); + country1.Models.Add(aus_state3); + country1.Models.Add(aus_state4); + + country2.Models.Add(brazil_state1); + country2.Models.Add(brazil_state2); + country2.Models.Add(brazil_state3); + + country3.Models.Add(china_state1); + country3.Models.Add(china_state2); + country3.Models.Add(china_state3); + country3.Models.Add(china_state4); + + country4.Models.Add(france_state1); + country4.Models.Add(france_state2); + country4.Models.Add(france_state3); + country4.Models.Add(france_state4); + + Items.Add(country1); + Items.Add(country2); + Items.Add(country3); + Items.Add(country4); + + checkedStates.Add(aus_state1); + checkedStates.Add(aus_state2); + checkedStates.Add(country2); + checkedStates.Add(country3); + } +} +```