Skip to content

Commit 866d83a

Browse files
ES-975464 - changes committed
1 parent c261bee commit 866d83a

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# how-to-bind-columns-from-view-model-in-wpf-and-uwp-treegrid-in-mvvm
1+
# How to Bind Columns from ViewModel in WPF / UWP TreeGrid in MVVM?
22

3-
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)
3+
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).
44

5-
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.
5+
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.
66

7-
## XAML code:
7+
### XAML:
88

99
```xml
1010
<syncfusion:SfTreeGrid Name="treeGrid"
@@ -20,23 +20,30 @@ You can bind the [SfTreeGrid.Columns](https://help.syncfusion.com/cr/wpf/Syncfus
2020
</syncfusion:SfTreeGrid>
2121
```
2222

23-
Refer to the following code example in which the TreeGrid column is populated with some `TreeGridTextColumn` when creating the ViewModel instance.
23+
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.
2424

25-
## C# code
25+
### C#:
2626

2727
```c#
2828
public class ViewModel: NotificationObject
2929
{
30+
#region Private Variables
31+
private ObservableCollection<EmployeeInfo> _employees;
3032
private TreeGridColumns sfGridColumns;
33+
#endregion
34+
3135
public TreeGridColumns SfGridColumns
3236
{
3337
get { return sfGridColumns; }
3438
set
35-
{ this.sfGridColumns = value;
39+
{
40+
this.sfGridColumns = value;
3641
RaisePropertyChanged("SfGridColumns");
3742
}
3843
}
3944

45+
#region ctr
46+
4047
public ViewModel()
4148
{
4249
this.Employees = GetEmployeesDetails();
@@ -47,5 +54,6 @@ public class ViewModel: NotificationObject
4754
sfGridColumns.Add(new TreeGridTextColumn() { MappingName = "Title" });
4855
sfGridColumns.Add(new TreeGridTextColumn() { MappingName = "Salary" });
4956
}
57+
#endregion
5058
}
5159
```

0 commit comments

Comments
 (0)