|
1 | | -# How to get the node in WPF TreeView (SfTreeView)? |
| 1 | +# How to Get the Node in WPF TreeView? |
2 | 2 |
|
3 | | -How to get the node in WPF TreeView (SfTreeView)? |
| 3 | +This sample illustrates how to get the node in [WPF TreeView](https://www.syncfusion.com/wpf-controls/treeview) (SfTreeView). |
4 | 4 |
|
5 | 5 | # About the sample |
6 | 6 |
|
7 | | -In SfTreeView, you can get the node based on the item bound with it using SfTreeView.GetItemInfo method. |
| 7 | +In `SfTreeView`, you can get the node based on the item bound with it using `SfTreeView.GetItemInfo` method. |
| 8 | + |
| 9 | +#### XAML |
| 10 | + |
| 11 | +``` xml |
| 12 | +<syncfusion:SfTreeView x:Name="sfTreeView" Grid.Row="1" ExpandActionTrigger="Node" AutoExpandMode="AllNodes" |
| 13 | + ChildPropertyName="SubFiles" |
| 14 | + FullRowSelect="True" |
| 15 | + ItemsSource="{Binding ImageNodeInfo}"> |
| 16 | + <syncfusion:SfTreeView.ItemTemplate> |
| 17 | + <DataTemplate> |
| 18 | + <Grid x:Name="grid"> |
| 19 | + <Grid Grid.Row="0"> |
| 20 | + <Grid.ColumnDefinitions> |
| 21 | + <ColumnDefinition Width="20" /> |
| 22 | + <ColumnDefinition Width="*" /> |
| 23 | + </Grid.ColumnDefinitions> |
| 24 | + <Grid> |
| 25 | + <Image Source="{Binding ImageIcon}" |
| 26 | + VerticalAlignment="Center" |
| 27 | + HorizontalAlignment="Center" |
| 28 | + Height="16" |
| 29 | + Width="16"/> |
| 30 | + </Grid> |
| 31 | + <Grid Grid.Column="1" |
| 32 | + Margin="1,0,0,0" |
| 33 | + VerticalAlignment="Center"> |
| 34 | + <TextBlock Text="{Binding ItemName}" |
| 35 | + Foreground="Black" |
| 36 | + FontSize="13" |
| 37 | + VerticalAlignment="Center" /> |
| 38 | + </Grid> |
| 39 | + </Grid> |
| 40 | + </Grid> |
| 41 | + </DataTemplate> |
| 42 | + </syncfusion:SfTreeView.ItemTemplate> |
| 43 | +</syncfusion:SfTreeView> |
| 44 | +``` |
| 45 | + |
| 46 | +#### C# |
8 | 47 |
|
9 | 48 | ```c# |
10 | 49 | var treeViewInfo = sfTreeView.GetItemInfo((this.DataContext as FileManagerViewModel).ImageNodeInfo.FirstOrDefault(x => x.ItemName == "Documents")); |
11 | 50 | var node = treeViewInfo.Node; |
12 | 51 | ``` |
13 | 52 |
|
14 | | -KB article - [How to get the node in WPF TreeView (SfTreeView)?](https://www.syncfusion.com/kb/11991/how-to-get-the-node-in-wpf-treeview-sftreeview) |
15 | | - |
16 | 53 | ## Requirements to run the demo |
17 | 54 | Visual Studio 2015 and above versions |
0 commit comments