|
1 | 1 | # how-to-sort-the-TreeView-node-in-SfTreeView |
2 | | -This project contains the source code for the Chat control in .NET WPF, Winforms, and WinUI platforms. |
| 2 | +This repository demonstrates how to sort the treeview nodes in SfTreeView. |
| 3 | + |
| 4 | +## Sample |
| 5 | + |
| 6 | +### XAML |
| 7 | + |
| 8 | +```xaml |
| 9 | + <Button Text="Sort TreeView" Command="{Binding TreeViewSortCommand}" HeightRequest="50" Grid.Row="0" /> |
| 10 | + <syncfusion:SfTreeView x:Name="treeView" Grid.Row="1" ChildPropertyName="SubFiles" ItemTemplateContextType="Node" AutoExpandMode="AllNodesExpanded" ItemsSource="{Binding ImageNodeInfo}"> |
| 11 | + <syncfusion:SfTreeView.ItemTemplate> |
| 12 | + <DataTemplate> |
| 13 | + <Grid x:Name="grid" RowSpacing="0" > |
| 14 | + <Grid.ColumnDefinitions> |
| 15 | + <ColumnDefinition Width="40" /> |
| 16 | + <ColumnDefinition Width="*" /> |
| 17 | + </Grid.ColumnDefinitions> |
| 18 | + <Image Source="{Binding Content.ImageIcon}" VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="35" WidthRequest="35"/> |
| 19 | + <Grid Grid.Column="1" RowSpacing="1" Padding="1,0,0,0" VerticalOptions="Center"> |
| 20 | + <Label LineBreakMode="NoWrap" Text="{Binding Content.ItemName}" VerticalTextAlignment="Center"/> |
| 21 | + </Grid> |
| 22 | + </Grid> |
| 23 | + </DataTemplate> |
| 24 | + </syncfusion:SfTreeView.ItemTemplate> |
| 25 | + </syncfusion:SfTreeView> |
| 26 | +``` |
| 27 | +### View Model |
| 28 | + |
| 29 | +```csharp |
| 30 | + public class FileManagerViewModel : INotifyPropertyChanged |
| 31 | + { |
| 32 | + #region Fields |
| 33 | + |
| 34 | + private ObservableCollection<FileManager> imageNodeInfo; |
| 35 | + |
| 36 | + #endregion |
| 37 | + |
| 38 | + #region Constructor |
| 39 | + |
| 40 | + public FileManagerViewModel() |
| 41 | + { |
| 42 | + TreeViewSortCommand = new Command(OnTreeViewSortClicked); |
| 43 | + GenerateSource(); |
| 44 | + } |
| 45 | + |
| 46 | + #endregion |
| 47 | + |
| 48 | + #region Properties |
| 49 | + |
| 50 | + public ObservableCollection<FileManager> ImageNodeInfo |
| 51 | + { |
| 52 | + get |
| 53 | + { |
| 54 | + return imageNodeInfo; |
| 55 | + } |
| 56 | + set |
| 57 | + { |
| 58 | + this.imageNodeInfo = value; |
| 59 | + this.RaisedOnPropertyChanged("ImageNodeInfo"); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + public Command TreeViewSortCommand { get; set; } |
| 64 | + |
| 65 | + #endregion |
| 66 | + |
| 67 | + #region Command method |
| 68 | + |
| 69 | + private void OnTreeViewSortClicked(object obj) |
| 70 | + { |
| 71 | + this.ImageNodeInfo = new ObservableCollection<FileManager>(ImageNodeInfo.OrderBy(i => i.ItemName)); |
| 72 | + } |
| 73 | +} |
| 74 | +``` |
| 75 | +## Requirements to run the demo |
| 76 | + |
| 77 | +To run the demo, refer to [System Requirements for .NET MAUI](https://help.syncfusion.com/maui/system-requirements). |
| 78 | + |
| 79 | +Make sure that you have the compatible versions of [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/ ) with the Dot NET MAUI workload and [.NET Core SDK 7.0](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) or later version in your machine before starting to work on this project. |
| 80 | + |
| 81 | +## Troubleshooting: |
| 82 | +### Path too long exception |
| 83 | + |
| 84 | +If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project. |
| 85 | + |
| 86 | +## License |
| 87 | + |
| 88 | +Syncfusion® has no liability for any damage or consequence that may arise from using or viewing the samples. The samples are for demonstrative purposes. If you choose to use or access the samples, you agree to not hold Syncfusion® liable, in any form, for any damage related to use, for accessing, or viewing the samples. By accessing, viewing, or seeing the samples, you acknowledge and agree Syncfusion®'s samples will not allow you seek injunctive relief in any form for any claim related to the sample. If you do not agree to this, do not view, access, utilize, or otherwise do anything with Syncfusion®'s samples. |
0 commit comments