### Sample Self-Referenced JSON Data Source: https://context7.com/devexpress-examples/maui-tree-view/llms.txt Provides a sample JSON structure for self-referenced employee data. Each object has an `Id` and a `ParentId` to define the hierarchical relationships within the dataset. ```json // Data/Employees.json - Sample self-referenced data (embedded resource) [ { "Id": 109, "ParentId": 0, "FirstName": "Bruce", "LastName": "Cambell", "JobTitle": "Chief Executive Officer", "Phone": "(417) 166-3268", "EmailAddress": "Bruce_Cambell@example.com", "City": "Tokyo", "CountryRegionName": "Japan", "GroupName": "Executive General and Administration" }, { "Id": 42, "ParentId": 109, "FirstName": "Cindy", "LastName": "Haneline", "JobTitle": "Information Services Manager", "City": "Singapore", "CountryRegionName": "Singapore" }, { "Id": 117, "ParentId": 42, "FirstName": "Andrea", "LastName": "Deville", "JobTitle": "Database Administrator", "City": "London", "CountryRegionName": "United Kingdom" } ] ``` -------------------------------- ### Load Flat Data from JSON (C#) Source: https://context7.com/devexpress-examples/maui-tree-view/llms.txt Implements the `EmployeesRepository` class to load flat employee data from an embedded JSON resource. It uses `System.Text.Json` for deserialization into a list of `Employee` objects. ```csharp // Data/EmployeesRepository.cs - Load flat data from embedded JSON using System.Collections.Generic; using System.IO; using System.Text.Json; namespace TreeView.SelfReference.Data { public class EmployeesRepository { public IList Employees { get; private set; } public EmployeesRepository() { System.Reflection.Assembly assembly = GetType().Assembly; Stream stream = assembly.GetManifestResourceStream("Employees.json"); Employees = JsonSerializer.Deserialize>(stream); } } } ``` -------------------------------- ### ViewModel for TreeView Data (C#) Source: https://context7.com/devexpress-examples/maui-tree-view/llms.txt The `TreeViewModel` class initializes the `EmployeesRepository` and exposes an `ObservableCollection` named `Nodes`. This collection is used to bind data to the MAUI TreeView. ```csharp // ViewModels/TreeViewModel.cs using System.Collections.ObjectModel; using TreeView.SelfReference.Data; namespace TreeViewWithSelfReferenceData; public class TreeViewModel { public ObservableCollection Nodes { get; } public TreeViewModel() { var r = new EmployeesRepository(); Nodes = new(r.Employees); } } ``` -------------------------------- ### Define Hierarchical Data Model in C# Source: https://context7.com/devexpress-examples/maui-tree-view/llms.txt Defines the `ReportLibraryNode` class, a model for hierarchical data. Each node has a `Name` and an `ObservableCollection` of child `ReportLibraryNode` objects, enabling nested structures. ```csharp // Data/ReportLibraryNode.cs - Node model with nested children using System.Collections.ObjectModel; namespace TreeView.Data; public class ReportLibraryNode { public string Name { get; set; } public ObservableCollection Nodes { get; } public ReportLibraryNode() { Nodes = new(); } } ``` -------------------------------- ### Configure DevExpress TreeView Services in MAUI Application Source: https://context7.com/devexpress-examples/maui-tree-view/llms.txt Sets up the MAUI application builder to integrate DevExpress TreeView services and theming. This involves calling specific extension methods on the MauiAppBuilder to enable the necessary DevExpress components and features for the application. ```csharp // MauiProgram.cs using DevExpress.Maui; using DevExpress.Maui.Core; using Microsoft.Maui.Controls.Hosting; using Microsoft.Maui.Hosting; namespace TreeViewApp { public static class MauiProgram { public static MauiApp CreateMauiApp() { // Enable system bar theming ThemeManager.ApplyThemeToSystemBars = true; var builder = MauiApp.CreateBuilder(); builder .UseMauiApp() .UseDevExpressCollectionView() .UseDevExpressTreeView() // Required for DXTreeView .UseDevExpressControls() .UseDevExpressEditors() .UseDevExpress(useLocalization: true) .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("roboto-regular.ttf", "Roboto"); }); return builder.Build(); } } } ``` -------------------------------- ### Load Raw Asset from Application Package (C#) Source: https://github.com/devexpress-examples/maui-tree-view/blob/24.2.3+/CS/TreeViewWithHierarchicalData/CS/Resources/Raw/AboutAssets.txt This C# code snippet shows how to load and read the contents of a raw asset that has been deployed with the application package. It utilizes the `FileSystem.OpenAppPackageFileAsync` method from the Essentials library to get a stream to the asset and then reads its content using a `StreamReader`. Ensure that the asset file name matches the one specified in the `MauiAsset` configuration. ```csharp async Task LoadMauiAsset() { using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt"); using var reader = new StreamReader(stream); var contents = reader.ReadToEnd(); } ``` -------------------------------- ### Configure .NET MAUI Project with DevExpress TreeView Source: https://context7.com/devexpress-examples/maui-tree-view/llms.txt This XML snippet shows the .NET MAUI project file configuration. It includes settings for target frameworks, application metadata, resource embedding, and crucially, the addition of the DevExpress.Maui.TreeView NuGet package. Ensure the DevExpress NuGet feed is registered to resolve this package. ```xml net9.0-android;net9.0-ios Exe true enable true TreeViewApp TreeViewApp com.companyname.TreeViewApp 1.0 1 14.2 21.0 9.0.10 Employees.json ``` -------------------------------- ### Generate Hierarchical Data in C# Source: https://context7.com/devexpress-examples/maui-tree-view/llms.txt Provides a static factory method `Generate()` within `ReportLibraryData` to create a sample hierarchical data structure. This method constructs nested `ReportLibraryNode` objects representing categories, subcategories, and files. ```csharp // Data/ReportLibraryData.cs - Factory to create hierarchical data using System.Collections.ObjectModel; namespace TreeView.Data; public static class ReportLibraryData { public static ReportLibraryNode Generate() { var root = new ReportLibraryNode(); // Create category nodes var customers = new ReportLibraryNode() { Name = "Customers" }; var employees = new ReportLibraryNode() { Name = "Employees" }; var products = new ReportLibraryNode() { Name = "Products" }; // Create nested subcategory var orders = new ReportLibraryNode() { Name = "Orders" }; orders.Nodes.Add(new ReportLibraryNode() { Name = "Detail.pdf" }); orders.Nodes.Add(new ReportLibraryNode() { Name = "Summary.pdf" }); // Build hierarchy customers.Nodes.Add(orders); customers.Nodes.Add(new ReportLibraryNode() { Name = "Balance sheet.pdf" }); employees.Nodes.Add(new ReportLibraryNode() { Name = "Employee comparison.pdf" }); employees.Nodes.Add(new ReportLibraryNode() { Name = "Performance review.pdf" }); // Create deeper nesting for products var barCodes = new ReportLibraryNode() { Name = "Bar Codes" }; barCodes.Nodes.Add(new ReportLibraryNode() { Name = "Product label.pdf" }); products.Nodes.Add(barCodes); root.Nodes.Add(customers); root.Nodes.Add(employees); root.Nodes.Add(products); return root; } } ``` -------------------------------- ### ViewModel for Hierarchical TreeView Data in C# Source: https://context7.com/devexpress-examples/maui-tree-view/llms.txt The `TreeViewModel` class initializes the `ReportLibraryNode` hierarchy using `ReportLibraryData.Generate()`. It exposes the root node's `Nodes` collection as an `ObservableCollection` for binding to the TreeView. ```csharp // ViewModels/TreeViewModel.cs using System.Collections.ObjectModel; using TreeView.Data; namespace TreeViewWithHierarchicalData; public class TreeViewModel { public ObservableCollection Nodes => root.Nodes; public TreeViewModel() { root = ReportLibraryData.Generate(); } ReportLibraryNode root; } ``` -------------------------------- ### Define Self-Referenced Data Model (C#) Source: https://context7.com/devexpress-examples/maui-tree-view/llms.txt Defines the `Employee` class, a flat data model with `Id` and `ParentId` properties to establish self-referencing relationships for the TreeView. It includes employee details and computed properties for display. ```csharp // Data/Employee.cs - Flat data model with self-reference keys using System; using System.Text.Json.Serialization; using Microsoft.Maui.Controls; namespace TreeView.SelfReference.Data { public class Employee { public Employee() { } // Key fields for building tree structure public int Id { get; set; } public int ParentId { get; set; } // ParentId = 0 indicates root node // Employee properties public string FirstName { get; set; } public string LastName { get; set; } public string JobTitle { get; set; } public string Phone { get; set; } public string EmailAddress { get; set; } public string City { get; set; } public string CountryRegionName { get; set; } public string GroupName { get; set; } public DateTime BirthDate { get; set; } public DateTime HireDate { get; set; } // Computed display property public string FullName => FirstName + " " + LastName; // Image handling from JSON public string ImageData { set => Image = ImageSource.FromFile(value); } [JsonIgnore] public ImageSource Image { get; set; } [JsonIgnore] public string Relationship => $"Id: {Id}, ParentId: {ParentId}"; } } ``` -------------------------------- ### Configure MAUI TreeView with Self-Referenced Data (XAML) Source: https://context7.com/devexpress-examples/maui-tree-view/llms.txt Configures the `DXTreeView` in XAML to display self-referenced data. It binds to the `Nodes` collection from the `TreeViewModel` and uses `SelfReferenceTreeDescription` to define the hierarchy based on `Id` and `ParentId` fields. Sorting by `FullName` is also applied. ```xml ``` -------------------------------- ### Configure MAUI TreeView for Hierarchical Data in XAML Source: https://context7.com/devexpress-examples/maui-tree-view/llms.txt This XAML snippet configures the `DXTreeView` to display hierarchical data. It binds `ItemsSource` to the `Nodes` property of the `TreeViewModel`, sets `DisplayMember` to 'Name', and uses `HierarchyTreeDescription` with `ChildNodeFieldName='Nodes'` to specify how child nodes are located. ```xml ``` -------------------------------- ### Include Raw Assets with MauiAsset Build Action (.NET MAUI) Source: https://github.com/devexpress-examples/maui-tree-view/blob/24.2.3+/CS/TreeViewWithHierarchicalData/CS/Resources/Raw/AboutAssets.txt This snippet demonstrates how to configure the `.csproj` file to include raw assets in your .NET MAUI application. The `MauiAsset` build action ensures that files in the specified directory (e.g., `ResourcesRaw**`) are deployed with the application package. The `LogicalName` property allows for custom naming and organization of deployed assets. ```xml ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.