From c261bee7feaab89c3e6fbfc4919caed5201d7fe3 Mon Sep 17 00:00:00 2001 From: Sreemon Premkumar M Date: Thu, 14 Aug 2025 18:47:52 +0530 Subject: [PATCH 1/3] ES-975464 - Resolve ReadMe Length Issues in this repository --- README.md | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2020973..0183c0a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,51 @@ # how-to-bind-columns-from-view-model-in-wpf-and-uwp-treegrid-in-mvvm -This example illustrates to bind the columns from view model. \ No newline at end of file +This example illustrates to bind the columns from ViewmModel in [WPF TreeGrid](https://www.syncfusion.com/wpf-controls/treegrid) and [UWP TreeGrid](https://www.syncfusion.com/uwp-ui-controls/treegrid) + +You can bind the [SfTreeGrid.Columns](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.SfTreeGrid.html#Syncfusion_UI_Xaml_TreeGrid_SfTreeGrid_Columns) property in ViewModel by having the binding property of `Syncfusion.SfGrid.UI.Xaml.TreeGrid.Columns` type. Thus, you can set binding to the `SfTreeGrid.Columns` property that provides DataContext of `TreeGrid` in ViewModel. + +## XAML code: + +```xml + + +``` + +Refer to the following code example in which the TreeGrid column is populated with some `TreeGridTextColumn` when creating the ViewModel instance. + +## C# code + +```c# +public class ViewModel: NotificationObject +{ + private TreeGridColumns sfGridColumns; + public TreeGridColumns SfGridColumns + { + get { return sfGridColumns; } + set + { this.sfGridColumns = value; + RaisePropertyChanged("SfGridColumns"); + } + } + + public ViewModel() + { + this.Employees = GetEmployeesDetails(); + rowDataCommand = new RelayCommand(ChangeCanExecute); + this.sfGridColumns = new TreeGridColumns(); + sfGridColumns.Add(new TreeGridTextColumn() { MappingName = "FirstName" }); + sfGridColumns.Add(new TreeGridTextColumn() { MappingName = "LastName" }); + sfGridColumns.Add(new TreeGridTextColumn() { MappingName = "Title" }); + sfGridColumns.Add(new TreeGridTextColumn() { MappingName = "Salary" }); + } +} +``` \ No newline at end of file From 866d83acdde6bdb93ebd33e613a3969a34e107f5 Mon Sep 17 00:00:00 2001 From: SreemonPremkumarMuthukrishnan Date: Wed, 22 Oct 2025 10:37:12 +0530 Subject: [PATCH 2/3] ES-975464 - changes committed --- README.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0183c0a..297a6e7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# how-to-bind-columns-from-view-model-in-wpf-and-uwp-treegrid-in-mvvm +# How to Bind Columns from ViewModel in WPF / UWP TreeGrid in MVVM? -This example illustrates to bind the columns from ViewmModel in [WPF TreeGrid](https://www.syncfusion.com/wpf-controls/treegrid) and [UWP TreeGrid](https://www.syncfusion.com/uwp-ui-controls/treegrid) +This example illustrates to bind the columns from ViewModel in [WPF TreeGrid](https://www.syncfusion.com/wpf-controls/treegrid) and [UWP TreeGrid](https://www.syncfusion.com/uwp-ui-controls/treegrid) (SfTreeGrid). -You can bind the [SfTreeGrid.Columns](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.SfTreeGrid.html#Syncfusion_UI_Xaml_TreeGrid_SfTreeGrid_Columns) property in ViewModel by having the binding property of `Syncfusion.SfGrid.UI.Xaml.TreeGrid.Columns` type. Thus, you can set binding to the `SfTreeGrid.Columns` property that provides DataContext of `TreeGrid` in ViewModel. +You can bind the [SfTreeGrid.Columns](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.SfTreeGrid.html#Syncfusion_UI_Xaml_TreeGrid_SfTreeGrid_Columns) property in ViewModel by having the binding property of **Syncfusion.SfGrid.UI.Xaml.TreeGrid.Columns** type. Thus, you can set binding to the **SfTreeGrid.Columns** property that provides DataContext of TreeGrid in ViewModel. -## XAML code: +### XAML: ```xml ``` -Refer to the following code example in which the TreeGrid column is populated with some `TreeGridTextColumn` when creating the ViewModel instance. +Refer to the following code example in which the TreeGrid column is populated with some [TreeGridTextColumn](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.TreeGridTextColumn.html) when creating the ViewModel instance. -## C# code +### C#: ```c# public class ViewModel: NotificationObject { + #region Private Variables + private ObservableCollection _employees; private TreeGridColumns sfGridColumns; + #endregion + public TreeGridColumns SfGridColumns { get { return sfGridColumns; } set - { this.sfGridColumns = value; + { + this.sfGridColumns = value; RaisePropertyChanged("SfGridColumns"); } } + #region ctr + public ViewModel() { this.Employees = GetEmployeesDetails(); @@ -47,5 +54,6 @@ public class ViewModel: NotificationObject sfGridColumns.Add(new TreeGridTextColumn() { MappingName = "Title" }); sfGridColumns.Add(new TreeGridTextColumn() { MappingName = "Salary" }); } + #endregion } ``` \ No newline at end of file From c6798cbcf5bccfb2c7bf6699253038276241104a Mon Sep 17 00:00:00 2001 From: SreemonPremkumarM Date: Wed, 22 Oct 2025 22:50:49 +0530 Subject: [PATCH 3/3] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 297a6e7..7c50cc9 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,11 @@ Refer to the following code example in which the TreeGrid column is populated wi public class ViewModel: NotificationObject { #region Private Variables + private ObservableCollection _employees; + private TreeGridColumns sfGridColumns; + #endregion public TreeGridColumns SfGridColumns @@ -56,4 +59,4 @@ public class ViewModel: NotificationObject } #endregion } -``` \ No newline at end of file +```