├── MauiTreeView
├── Resources
│ ├── Images
│ │ ├── item.png
│ │ ├── blank.png
│ │ ├── openglyph.png
│ │ ├── folderopen.png
│ │ ├── collpsedglyph.png
│ │ ├── folderclosed.png
│ │ └── dotnet_bot.svg
│ ├── Fonts
│ │ ├── OpenSans-Regular.ttf
│ │ └── OpenSans-Semibold.ttf
│ ├── AppIcon
│ │ ├── appicon.svg
│ │ └── appiconfg.svg
│ ├── Raw
│ │ └── AboutAssets.txt
│ ├── Splash
│ │ └── splash.svg
│ └── Styles
│ │ ├── Colors.xaml
│ │ └── Styles.xaml
├── AppShell.xaml.cs
├── Properties
│ └── launchSettings.json
├── App.xaml.cs
├── Sample
│ ├── Models
│ │ ├── Company.cs
│ │ ├── Employee.cs
│ │ └── Department.cs
│ ├── Views
│ │ ├── CompanyPage.xaml
│ │ └── CompanyPage.xaml.cs
│ ├── Helpers
│ │ └── CompanyTreeViewBuilder.cs
│ └── Services
│ │ └── DataService.cs
├── Models
│ ├── XamlItem.cs
│ └── XamlItemGroup.cs
├── Platforms
│ ├── Android
│ │ ├── Resources
│ │ │ └── values
│ │ │ │ └── colors.xml
│ │ ├── MainApplication.cs
│ │ ├── AndroidManifest.xml
│ │ └── MainActivity.cs
│ ├── iOS
│ │ ├── AppDelegate.cs
│ │ ├── Program.cs
│ │ └── Info.plist
│ ├── MacCatalyst
│ │ ├── AppDelegate.cs
│ │ ├── Program.cs
│ │ └── Info.plist
│ ├── Windows
│ │ ├── App.xaml
│ │ ├── app.manifest
│ │ ├── App.xaml.cs
│ │ └── Package.appxmanifest
│ └── Tizen
│ │ ├── Main.cs
│ │ └── tizen-manifest.xml
├── MainPage.xaml.cs
├── AppShell.xaml
├── App.xaml
├── MauiProgram.cs
├── Controls
│ ├── ResourceImage.cs
│ ├── ExpandButtonContent.cs
│ ├── TreeView.cs
│ └── TreeViewNode.cs
├── MainPage.xaml
└── MauiTreeView.csproj
├── MauiTreeView.sln
├── .gitattributes
└── .gitignore
/MauiTreeView/Resources/Images/item.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icebeam7/MauiTreeView/HEAD/MauiTreeView/Resources/Images/item.png
--------------------------------------------------------------------------------
/MauiTreeView/Resources/Images/blank.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icebeam7/MauiTreeView/HEAD/MauiTreeView/Resources/Images/blank.png
--------------------------------------------------------------------------------
/MauiTreeView/Resources/Images/openglyph.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icebeam7/MauiTreeView/HEAD/MauiTreeView/Resources/Images/openglyph.png
--------------------------------------------------------------------------------
/MauiTreeView/Resources/Images/folderopen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icebeam7/MauiTreeView/HEAD/MauiTreeView/Resources/Images/folderopen.png
--------------------------------------------------------------------------------
/MauiTreeView/Resources/Images/collpsedglyph.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icebeam7/MauiTreeView/HEAD/MauiTreeView/Resources/Images/collpsedglyph.png
--------------------------------------------------------------------------------
/MauiTreeView/Resources/Images/folderclosed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icebeam7/MauiTreeView/HEAD/MauiTreeView/Resources/Images/folderclosed.png
--------------------------------------------------------------------------------
/MauiTreeView/Resources/Fonts/OpenSans-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icebeam7/MauiTreeView/HEAD/MauiTreeView/Resources/Fonts/OpenSans-Regular.ttf
--------------------------------------------------------------------------------
/MauiTreeView/Resources/Fonts/OpenSans-Semibold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icebeam7/MauiTreeView/HEAD/MauiTreeView/Resources/Fonts/OpenSans-Semibold.ttf
--------------------------------------------------------------------------------
/MauiTreeView/AppShell.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace MauiTreeView;
2 |
3 | public partial class AppShell : Shell
4 | {
5 | public AppShell()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/MauiTreeView/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "Windows Machine": {
4 | "commandName": "MsixPackage",
5 | "nativeDebugging": false
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/MauiTreeView/App.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace MauiTreeView;
2 |
3 | public partial class App : Application
4 | {
5 | public App()
6 | {
7 | InitializeComponent();
8 |
9 | MainPage = new AppShell();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/MauiTreeView/Sample/Models/Company.cs:
--------------------------------------------------------------------------------
1 | //S1
2 | namespace MauiTreeView.Sample.Models
3 | {
4 | public class Company
5 | {
6 | public int CompanyId { get; set; }
7 | public string CompanyName { get; set; }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/MauiTreeView/Models/XamlItem.cs:
--------------------------------------------------------------------------------
1 | //0 images
2 | //1
3 |
4 | namespace MauiTreeView.Models
5 | {
6 | [Serializable]
7 | public class XamlItem
8 | {
9 | public string Key { get; set; }
10 | public int ItemId { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/MauiTreeView/Resources/AppIcon/appicon.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/Android/Resources/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #512BD4
4 | #2B0B98
5 | #2B0B98
6 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/iOS/AppDelegate.cs:
--------------------------------------------------------------------------------
1 | using Foundation;
2 |
3 | namespace MauiTreeView;
4 |
5 | [Register("AppDelegate")]
6 | public class AppDelegate : MauiUIApplicationDelegate
7 | {
8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
9 | }
10 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/MacCatalyst/AppDelegate.cs:
--------------------------------------------------------------------------------
1 | using Foundation;
2 |
3 | namespace MauiTreeView;
4 |
5 | [Register("AppDelegate")]
6 | public class AppDelegate : MauiUIApplicationDelegate
7 | {
8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
9 | }
10 |
--------------------------------------------------------------------------------
/MauiTreeView/Sample/Models/Employee.cs:
--------------------------------------------------------------------------------
1 | //S3
2 | namespace MauiTreeView.Sample.Models
3 | {
4 | public class Employee
5 | {
6 | public int EmployeeId { get; set; }
7 | public string EmployeeName { get; set; }
8 | public int DepartmentId { get; set; }
9 | }
10 | }
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/Windows/App.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/MauiTreeView/Sample/Models/Department.cs:
--------------------------------------------------------------------------------
1 | //S2
2 | namespace MauiTreeView.Sample.Models
3 | {
4 | public class Department
5 | {
6 | public int DepartmentId { get; set; }
7 | public string DepartmentName { get; set; }
8 | public int ParentDepartmentId { get; set; }
9 | public int CompanyId { get; set; }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/MauiTreeView/Models/XamlItemGroup.cs:
--------------------------------------------------------------------------------
1 | //2
2 | namespace MauiTreeView.Models
3 | {
4 | [Serializable]
5 | public class XamlItemGroup
6 | {
7 | public List Children { get; } = new ();
8 | public List XamlItems { get; } = new ();
9 |
10 | public string Name { get; set; }
11 | public int GroupId { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/Tizen/Main.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Maui;
3 | using Microsoft.Maui.Hosting;
4 |
5 | namespace MauiTreeView;
6 |
7 | class Program : MauiApplication
8 | {
9 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
10 |
11 | static void Main(string[] args)
12 | {
13 | var app = new Program();
14 | app.Run(args);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/Android/MainApplication.cs:
--------------------------------------------------------------------------------
1 | using Android.App;
2 | using Android.Runtime;
3 |
4 | namespace MauiTreeView;
5 |
6 | [Application]
7 | public class MainApplication : MauiApplication
8 | {
9 | public MainApplication(IntPtr handle, JniHandleOwnership ownership)
10 | : base(handle, ownership)
11 | {
12 | }
13 |
14 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
15 | }
16 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/iOS/Program.cs:
--------------------------------------------------------------------------------
1 | using ObjCRuntime;
2 | using UIKit;
3 |
4 | namespace MauiTreeView;
5 |
6 | public class Program
7 | {
8 | // This is the main entry point of the application.
9 | static void Main(string[] args)
10 | {
11 | // if you want to use a different Application Delegate class from "AppDelegate"
12 | // you can specify it here.
13 | UIApplication.Main(args, null, typeof(AppDelegate));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/MacCatalyst/Program.cs:
--------------------------------------------------------------------------------
1 | using ObjCRuntime;
2 | using UIKit;
3 |
4 | namespace MauiTreeView;
5 |
6 | public class Program
7 | {
8 | // This is the main entry point of the application.
9 | static void Main(string[] args)
10 | {
11 | // if you want to use a different Application Delegate class from "AppDelegate"
12 | // you can specify it here.
13 | UIApplication.Main(args, null, typeof(AppDelegate));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/Android/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/Android/MainActivity.cs:
--------------------------------------------------------------------------------
1 | using Android.App;
2 | using Android.Content.PM;
3 | using Android.OS;
4 |
5 | namespace MauiTreeView;
6 |
7 | [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
8 | public class MainActivity : MauiAppCompatActivity
9 | {
10 | }
11 |
--------------------------------------------------------------------------------
/MauiTreeView/MainPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace MauiTreeView;
2 |
3 | public partial class MainPage : ContentPage
4 | {
5 | int count = 0;
6 |
7 | public MainPage()
8 | {
9 | InitializeComponent();
10 | }
11 |
12 | private void OnCounterClicked(object sender, EventArgs e)
13 | {
14 | count++;
15 |
16 | if (count == 1)
17 | CounterBtn.Text = $"Clicked {count} time";
18 | else
19 | CounterBtn.Text = $"Clicked {count} times";
20 |
21 | SemanticScreenReader.Announce(CounterBtn.Text);
22 | }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/MauiTreeView/Sample/Views/CompanyPage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/MauiTreeView/AppShell.xaml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/MauiTreeView/App.xaml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/MauiTreeView/Resources/Raw/AboutAssets.txt:
--------------------------------------------------------------------------------
1 | Any raw assets you want to be deployed with your application can be placed in
2 | this directory (and child directories). Deployment of the asset to your application
3 | is automatically handled by the following `MauiAsset` Build Action within your `.csproj`.
4 |
5 |
6 |
7 | These files will be deployed with you package and will be accessible using Essentials:
8 |
9 | async Task LoadMauiAsset()
10 | {
11 | using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt");
12 | using var reader = new StreamReader(stream);
13 |
14 | var contents = reader.ReadToEnd();
15 | }
16 |
--------------------------------------------------------------------------------
/MauiTreeView/MauiProgram.cs:
--------------------------------------------------------------------------------
1 | using MauiTreeView.Sample.Helpers;
2 | using MauiTreeView.Sample.Services;
3 | using MauiTreeView.Sample.Views;
4 |
5 | namespace MauiTreeView;
6 |
7 | public static class MauiProgram
8 | {
9 | public static MauiApp CreateMauiApp()
10 | {
11 | var builder = MauiApp.CreateBuilder();
12 | builder
13 | .UseMauiApp()
14 | .ConfigureFonts(fonts =>
15 | {
16 | fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
17 | fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
18 | });
19 |
20 | builder.Services.AddSingleton();
21 | builder.Services.AddSingleton();
22 | builder.Services.AddTransient();
23 |
24 | return builder.Build();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/Tizen/tizen-manifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | appicon.xhigh.png
7 |
8 |
9 |
10 |
11 | http://tizen.org/privilege/internet
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/Windows/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 | true/PM
12 | PerMonitorV2, PerMonitor
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/Windows/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.UI.Xaml;
2 |
3 | // To learn more about WinUI, the WinUI project structure,
4 | // and more about our project templates, see: http://aka.ms/winui-project-info.
5 |
6 | namespace MauiTreeView.WinUI;
7 |
8 | ///
9 | /// Provides application-specific behavior to supplement the default Application class.
10 | ///
11 | public partial class App : MauiWinUIApplication
12 | {
13 | ///
14 | /// Initializes the singleton application object. This is the first line of authored code
15 | /// executed, and as such is the logical equivalent of main() or WinMain().
16 | ///
17 | public App()
18 | {
19 | this.InitializeComponent();
20 | }
21 |
22 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/MauiTreeView/Sample/Views/CompanyPage.xaml.cs:
--------------------------------------------------------------------------------
1 | //S6 and S7
2 | using MauiTreeView.Sample.Services;
3 | using MauiTreeView.Sample.Helpers;
4 |
5 | namespace MauiTreeView.Sample.Views;
6 |
7 | public partial class CompanyPage : ContentPage
8 | {
9 | DataService service;
10 | CompanyTreeViewBuilder companyTreeViewBuilder;
11 |
12 | public CompanyPage(DataService service, CompanyTreeViewBuilder companyTreeViewBuilder)
13 | {
14 | InitializeComponent();
15 |
16 | this.service = service;
17 | this.companyTreeViewBuilder = companyTreeViewBuilder;
18 |
19 | ProcessTreeView();
20 | }
21 |
22 | private void ProcessTreeView()
23 | {
24 | var xamlItemGroups = companyTreeViewBuilder.GroupData(service);
25 | var rootNodes = TheTreeView.ProcessXamlItemGroups(xamlItemGroups);
26 | TheTreeView.RootNodes = rootNodes;
27 | }
28 | }
--------------------------------------------------------------------------------
/MauiTreeView/Controls/ResourceImage.cs:
--------------------------------------------------------------------------------
1 | //3
2 | namespace MauiTreeView.Controls
3 | {
4 | public class ResourceImage : Image
5 | {
6 | public static readonly BindableProperty ResourceProperty = BindableProperty.Create(nameof(Resource), typeof(string), typeof(string), null, BindingMode.OneWay, null, ResourceChanged);
7 |
8 | private static void ResourceChanged(BindableObject bindable, object oldvalue, object newvalue)
9 | {
10 | var resourceString = (string)newvalue;
11 | var imageControl = (Image)bindable;
12 |
13 | //imageControl.Source = ImageSource.FromResource(resourceString, Assembly.GetAssembly(typeof(ResourceImage)));
14 | imageControl.Source = ImageSource.FromFile(resourceString);
15 | }
16 |
17 | public string Resource
18 | {
19 | get => (string)GetValue(ResourceProperty);
20 | set => SetValue(ResourceProperty, value);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/MacCatalyst/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | UIDeviceFamily
6 |
7 | 1
8 | 2
9 |
10 | UIRequiredDeviceCapabilities
11 |
12 | arm64
13 |
14 | UISupportedInterfaceOrientations
15 |
16 | UIInterfaceOrientationPortrait
17 | UIInterfaceOrientationLandscapeLeft
18 | UIInterfaceOrientationLandscapeRight
19 |
20 | UISupportedInterfaceOrientations~ipad
21 |
22 | UIInterfaceOrientationPortrait
23 | UIInterfaceOrientationPortraitUpsideDown
24 | UIInterfaceOrientationLandscapeLeft
25 | UIInterfaceOrientationLandscapeRight
26 |
27 | XSAppIconAssets
28 | Assets.xcassets/appicon.appiconset
29 |
30 |
31 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | LSRequiresIPhoneOS
6 |
7 | UIDeviceFamily
8 |
9 | 1
10 | 2
11 |
12 | UIRequiredDeviceCapabilities
13 |
14 | arm64
15 |
16 | UISupportedInterfaceOrientations
17 |
18 | UIInterfaceOrientationPortrait
19 | UIInterfaceOrientationLandscapeLeft
20 | UIInterfaceOrientationLandscapeRight
21 |
22 | UISupportedInterfaceOrientations~ipad
23 |
24 | UIInterfaceOrientationPortrait
25 | UIInterfaceOrientationPortraitUpsideDown
26 | UIInterfaceOrientationLandscapeLeft
27 | UIInterfaceOrientationLandscapeRight
28 |
29 | XSAppIconAssets
30 | Assets.xcassets/appicon.appiconset
31 |
32 |
33 |
--------------------------------------------------------------------------------
/MauiTreeView.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.31611.283
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiTreeView", "MauiTreeView\MauiTreeView.csproj", "{57545D07-1EBF-4D83-8446-9C296256FBF4}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {57545D07-1EBF-4D83-8446-9C296256FBF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {57545D07-1EBF-4D83-8446-9C296256FBF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {57545D07-1EBF-4D83-8446-9C296256FBF4}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17 | {57545D07-1EBF-4D83-8446-9C296256FBF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
18 | {57545D07-1EBF-4D83-8446-9C296256FBF4}.Release|Any CPU.Build.0 = Release|Any CPU
19 | {57545D07-1EBF-4D83-8446-9C296256FBF4}.Release|Any CPU.Deploy.0 = Release|Any CPU
20 | EndGlobalSection
21 | GlobalSection(SolutionProperties) = preSolution
22 | HideSolutionNode = FALSE
23 | EndGlobalSection
24 | GlobalSection(ExtensibilityGlobals) = postSolution
25 | SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
26 | EndGlobalSection
27 | EndGlobal
28 |
--------------------------------------------------------------------------------
/MauiTreeView/Controls/ExpandButtonContent.cs:
--------------------------------------------------------------------------------
1 | // 4
2 | namespace MauiTreeView.Controls
3 | {
4 | //set what icons shows for expanded/Collapsed/Leafe Nodes or on request node expand icon (when ShowExpandButtonIfEmpty true).
5 | public class ExpandButtonContent : ContentView
6 | {
7 | protected override void OnBindingContextChanged()
8 | {
9 | base.OnBindingContextChanged();
10 |
11 | var node = BindingContext as TreeViewNode;
12 | bool isLeafNode = (node.ChildrenList == null || node.ChildrenList.Count == 0);
13 |
14 | //empty nodes have no icon to expand unless showExpandButtonIfEmpty is et to true which will show the expand
15 | //icon can click and populated node on demand propably using the expand event.
16 | if ((isLeafNode) && !node.ShowExpandButtonIfEmpty)
17 | {
18 | Content = new ResourceImage
19 | {
20 | Resource = isLeafNode ? "blank.png" : "folderopen.png",
21 | HeightRequest = 16,
22 | WidthRequest = 16
23 | };
24 | }
25 | else
26 | {
27 | Content = new ResourceImage
28 | {
29 | Resource = node.IsExpanded ? "openglyph.png" : "collpsedglyph.png",
30 | HeightRequest = 16,
31 | WidthRequest = 16
32 | };
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/MauiTreeView/MainPage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
11 |
12 |
17 |
18 |
23 |
24 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/MauiTreeView/Resources/Splash/splash.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/MauiTreeView/Resources/AppIcon/appiconfg.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/MauiTreeView/Platforms/Windows/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 | $placeholder$
12 | User Name
13 | $placeholder$.png
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/MauiTreeView/Resources/Styles/Colors.xaml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 | #512BD4
8 | #DFD8F7
9 | #2B0B98
10 | White
11 | Black
12 | #E1E1E1
13 | #C8C8C8
14 | #ACACAC
15 | #919191
16 | #6E6E6E
17 | #404040
18 | #212121
19 | #141414
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | #F7B548
35 | #FFD590
36 | #FFE5B9
37 | #28C2D1
38 | #7BDDEF
39 | #C3F2F4
40 | #3E8EED
41 | #72ACF1
42 | #A7CBF6
43 |
44 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/MauiTreeView/Sample/Helpers/CompanyTreeViewBuilder.cs:
--------------------------------------------------------------------------------
1 | //S5
2 | using MauiTreeView.Models;
3 | using MauiTreeView.Sample.Models;
4 | using MauiTreeView.Sample.Services;
5 |
6 | namespace MauiTreeView.Sample.Helpers
7 | {
8 | public class CompanyTreeViewBuilder
9 | {
10 | private XamlItemGroup FindParentDepartment(XamlItemGroup group, Department department)
11 | {
12 | if (group.GroupId == department.ParentDepartmentId)
13 | return group;
14 |
15 | if (group.Children != null)
16 | {
17 | foreach (var currentGroup in group.Children)
18 | {
19 | var search = FindParentDepartment(currentGroup, department);
20 |
21 | if (search != null)
22 | return search;
23 | }
24 | }
25 |
26 | return null;
27 | }
28 |
29 | public XamlItemGroup GroupData(DataService service)
30 | {
31 | var company = service.GetCompany();
32 | var departments = service.GetDepartments().OrderBy(x => x.ParentDepartmentId);
33 | var employees = service.GetEmployees();
34 |
35 | var companyGroup = new XamlItemGroup();
36 | companyGroup.Name = company.CompanyName;
37 |
38 | foreach (var dept in departments)
39 | {
40 | var itemGroup = new XamlItemGroup();
41 | itemGroup.Name = dept.DepartmentName;
42 | itemGroup.GroupId = dept.DepartmentId;
43 |
44 | // Employees first
45 | var employeesDepartment = employees.Where(x => x.DepartmentId == dept.DepartmentId);
46 |
47 | foreach (var emp in employeesDepartment)
48 | {
49 | var item = new XamlItem();
50 | item.ItemId = emp.EmployeeId;
51 | item.Key = emp.EmployeeName;
52 |
53 | itemGroup.XamlItems.Add(item);
54 | }
55 |
56 | // Departments now
57 | if (dept.ParentDepartmentId == -1)
58 | {
59 | companyGroup.Children.Add(itemGroup);
60 | }
61 | else
62 | {
63 | XamlItemGroup parentGroup = null;
64 |
65 | foreach (var group in companyGroup.Children)
66 | {
67 | parentGroup = FindParentDepartment(group, dept);
68 |
69 | if (parentGroup != null)
70 | {
71 | parentGroup.Children.Add(itemGroup);
72 | break;
73 | }
74 | }
75 | }
76 | }
77 |
78 | return companyGroup;
79 | }
80 | }
81 | }
--------------------------------------------------------------------------------
/MauiTreeView/Sample/Services/DataService.cs:
--------------------------------------------------------------------------------
1 | //S4
2 | using MauiTreeView.Sample.Models;
3 |
4 | namespace MauiTreeView.Sample.Services
5 | {
6 | public class DataService
7 | {
8 | public Company GetCompany()
9 | {
10 | return new Company()
11 | {
12 | CompanyId = 1,
13 | CompanyName = "TC Solutions"
14 | };
15 | }
16 |
17 | public IEnumerable GetDepartments()
18 | {
19 | return new List()
20 | {
21 | new Department() { CompanyId = 1, DepartmentId = 1, DepartmentName = "IT", ParentDepartmentId = -1 },
22 | new Department() { CompanyId = 1, DepartmentId = 2, DepartmentName = "Accounting", ParentDepartmentId = -1 },
23 | new Department() { CompanyId = 1, DepartmentId = 3, DepartmentName = "Production", ParentDepartmentId = -1 },
24 | new Department() { CompanyId = 1, DepartmentId = 4, DepartmentName = "Software", ParentDepartmentId = 1 },
25 | new Department() { CompanyId = 1, DepartmentId = 5, DepartmentName = "Support", ParentDepartmentId = 1 },
26 | new Department() { CompanyId = 1, DepartmentId = 6, DepartmentName = "Testing", ParentDepartmentId = 4 },
27 | new Department() { CompanyId = 1, DepartmentId = 7, DepartmentName = "Accounts receivable", ParentDepartmentId = 2 },
28 | new Department() { CompanyId = 1, DepartmentId = 8, DepartmentName = "Accounts payable", ParentDepartmentId = 2 },
29 | new Department() { CompanyId = 1, DepartmentId = 9, DepartmentName = "Customers and services", ParentDepartmentId = 8 }
30 | };
31 | }
32 |
33 | public IEnumerable GetEmployees()
34 | {
35 | return new List()
36 | {
37 | new Employee() { EmployeeId = 1, EmployeeName = "Luis", DepartmentId = 1 },
38 | new Employee() { EmployeeId = 2, EmployeeName = "Pepe", DepartmentId = 1 },
39 | new Employee() { EmployeeId = 3, EmployeeName = "Juan", DepartmentId = 2 },
40 | new Employee() { EmployeeId = 4, EmployeeName = "Inés", DepartmentId = 3 },
41 | new Employee() { EmployeeId = 5, EmployeeName = "Sara", DepartmentId = 3 },
42 | new Employee() { EmployeeId = 6, EmployeeName = "Sofy", DepartmentId = 4 },
43 | new Employee() { EmployeeId = 7, EmployeeName = "Hugo", DepartmentId = 5 },
44 | new Employee() { EmployeeId = 8, EmployeeName = "Gema", DepartmentId = 5 },
45 | new Employee() { EmployeeId = 9, EmployeeName = "Olga", DepartmentId = 6 },
46 | new Employee() { EmployeeId = 1, EmployeeName = "Otto", DepartmentId = 6 },
47 | new Employee() { EmployeeId = 2, EmployeeName = "Axel", DepartmentId = 6 },
48 | new Employee() { EmployeeId = 3, EmployeeName = "Eloy", DepartmentId = 7 },
49 | new Employee() { EmployeeId = 4, EmployeeName = "Flor", DepartmentId = 8 },
50 | new Employee() { EmployeeId = 5, EmployeeName = "Aída", DepartmentId = 9 },
51 | new Employee() { EmployeeId = 6, EmployeeName = "Ruth", DepartmentId = 9 }
52 | };
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/MauiTreeView/MauiTreeView.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0-android;net6.0-ios;net6.0-maccatalyst
5 | $(TargetFrameworks);net6.0-windows10.0.19041.0
6 |
7 |
8 | Exe
9 | MauiTreeView
10 | true
11 | true
12 | enable
13 |
14 |
15 | MauiTreeView
16 |
17 |
18 | com.companyname.mauitreeview
19 | 0B0E462F-1BB1-4436-B365-FCBC7DBC911A
20 |
21 |
22 | 1.0
23 | 1
24 |
25 | 14.2
26 | 14.0
27 | 21.0
28 | 10.0.17763.0
29 | 10.0.17763.0
30 | 6.5
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | MSBuild:Compile
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/MauiTreeView/Controls/TreeView.cs:
--------------------------------------------------------------------------------
1 | //6
2 | using MauiTreeView.Models;
3 | using System.Collections.ObjectModel;
4 | using System.Collections.Specialized;
5 |
6 | namespace MauiTreeView.Controls
7 | {
8 | public class TreeView : ScrollView
9 | {
10 | private readonly StackLayout _StackLayout = new StackLayout { Orientation = StackOrientation.Vertical };
11 |
12 | //TODO: This initialises the list, but there is nothing listening to INotifyCollectionChanged so no nodes will get rendered
13 | private IList _RootNodes = new ObservableCollection();
14 | private TreeViewNode _SelectedItem;
15 |
16 | ///
17 | /// The item that is selected in the tree
18 | /// TODO: Make this two way - and maybe eventually a bindable property
19 | ///
20 | public TreeViewNode SelectedItem
21 | {
22 | get => _SelectedItem;
23 |
24 | set
25 | {
26 | if (_SelectedItem == value)
27 | {
28 | return;
29 | }
30 |
31 | if (_SelectedItem != null)
32 | {
33 | _SelectedItem.IsSelected = false;
34 | }
35 |
36 | _SelectedItem = value;
37 |
38 | SelectedItemChanged?.Invoke(this, new EventArgs());
39 | }
40 | }
41 |
42 |
43 | public IList RootNodes
44 | {
45 | get => _RootNodes;
46 | set
47 | {
48 | _RootNodes = value;
49 |
50 | if (value is INotifyCollectionChanged notifyCollectionChanged)
51 | {
52 | notifyCollectionChanged.CollectionChanged += (s, e) =>
53 | {
54 | RenderNodes(_RootNodes, _StackLayout, e, null);
55 | };
56 | }
57 |
58 | RenderNodes(_RootNodes, _StackLayout, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset), null);
59 | }
60 | }
61 |
62 | ///
63 | /// Occurs when the user selects a TreeViewItem
64 | ///
65 | public event EventHandler SelectedItemChanged;
66 |
67 | public TreeView()
68 | {
69 | Content = _StackLayout;
70 | }
71 |
72 | private void RemoveSelectionRecursive(IEnumerable nodes)
73 | {
74 | foreach (var treeViewItem in nodes)
75 | {
76 | if (treeViewItem != SelectedItem)
77 | {
78 | treeViewItem.IsSelected = false;
79 | }
80 |
81 | RemoveSelectionRecursive(treeViewItem.ChildrenList);
82 | }
83 | }
84 |
85 | private static void AddItems(IEnumerable childTreeViewItems, StackLayout parent, TreeViewNode parentTreeViewItem)
86 | {
87 | foreach (var childTreeNode in childTreeViewItems)
88 | {
89 | if (!parent.Children.Contains(childTreeNode))
90 | {
91 | parent.Children.Add(childTreeNode);
92 | }
93 |
94 | childTreeNode.ParentTreeViewItem = parentTreeViewItem;
95 | }
96 | }
97 |
98 | ///
99 | /// TODO: A bit stinky but better than bubbling an event up...
100 | ///
101 | internal void ChildSelected(TreeViewNode child)
102 | {
103 | SelectedItem = child;
104 | child.IsSelected = true;
105 | child.SelectionBoxView.Color = child.SelectedBackgroundColor;
106 | child.SelectionBoxView.Opacity = child.SelectedBackgroundOpacity;
107 | RemoveSelectionRecursive(RootNodes);
108 | }
109 |
110 | internal static void RenderNodes(IEnumerable childTreeViewItems, StackLayout parent, NotifyCollectionChangedEventArgs e, TreeViewNode parentTreeViewItem)
111 | {
112 | if (e.Action != NotifyCollectionChangedAction.Add)
113 | {
114 | //TODO: Reintate this...
115 | //parent.Children.Clear();
116 | AddItems(childTreeViewItems, parent, parentTreeViewItem);
117 | }
118 | else
119 | {
120 | AddItems(e.NewItems.Cast(), parent, parentTreeViewItem);
121 | }
122 | }
123 |
124 | // Main code:
125 | private TreeViewNode CreateTreeViewNode(object bindingContext, Label label, bool isItem)
126 | {
127 | var node = new TreeViewNode
128 | {
129 | BindingContext = bindingContext,
130 | Content = new StackLayout
131 | {
132 | Children =
133 | {
134 | new ResourceImage
135 | {
136 | Resource = isItem? "item.png" :"folderopen.png" ,
137 | HeightRequest= 16,
138 | WidthRequest = 16
139 | },
140 | label
141 | },
142 | Orientation = StackOrientation.Horizontal
143 | }
144 | };
145 |
146 | //set DataTemplate for expand button content
147 | node.ExpandButtonTemplate = new DataTemplate(() => new ExpandButtonContent { BindingContext = node });
148 |
149 | return node;
150 | }
151 |
152 | private void CreateXamlItem(IList children, XamlItem xamlItem)
153 | {
154 | var label = new Label
155 | {
156 | VerticalOptions = LayoutOptions.Center,
157 | TextColor = Colors.Black
158 | };
159 | label.SetBinding(Label.TextProperty, "Key");
160 |
161 | var xamlItemTreeViewNode = CreateTreeViewNode(xamlItem, label, true);
162 | children.Add(xamlItemTreeViewNode);
163 | }
164 |
165 | /* private static void ProcessXamlItems(TreeViewNode node, XamlItemGroup xamlItemGroup)
166 | {
167 | var children = new ObservableCollection();
168 | foreach (var xamlItem in xamlItemGroup.XamlItems.OrderBy(xi => xi.Key))
169 | {
170 | CreateXamlItem(children, xamlItem);
171 | }
172 | node.ChildrenList = children;
173 | }
174 | */
175 | public ObservableCollection ProcessXamlItemGroups(XamlItemGroup xamlItemGroups)
176 | {
177 | var rootNodes = new ObservableCollection();
178 |
179 | foreach (var xamlItemGroup in xamlItemGroups.Children.OrderBy(xig => xig.Name))
180 | {
181 | var label = new Label
182 | {
183 | VerticalOptions = LayoutOptions.Center,
184 | TextColor = Colors.Black
185 | };
186 | label.SetBinding(Label.TextProperty, "Name");
187 |
188 | var groupTreeViewNode = CreateTreeViewNode(xamlItemGroup, label, false);
189 |
190 | rootNodes.Add(groupTreeViewNode);
191 |
192 | groupTreeViewNode.ChildrenList = ProcessXamlItemGroups(xamlItemGroup);
193 |
194 | foreach (var xamlItem in xamlItemGroup.XamlItems)
195 | {
196 | CreateXamlItem(groupTreeViewNode.ChildrenList, xamlItem);
197 | }
198 | }
199 |
200 | return rootNodes;
201 | }
202 | }
203 | }
204 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Oo]ut/
33 | [Ll]og/
34 | [Ll]ogs/
35 |
36 | # Visual Studio 2015/2017 cache/options directory
37 | .vs/
38 | # Uncomment if you have tasks that create the project's static files in wwwroot
39 | #wwwroot/
40 |
41 | # Visual Studio 2017 auto generated files
42 | Generated\ Files/
43 |
44 | # MSTest test Results
45 | [Tt]est[Rr]esult*/
46 | [Bb]uild[Ll]og.*
47 |
48 | # NUnit
49 | *.VisualState.xml
50 | TestResult.xml
51 | nunit-*.xml
52 |
53 | # Build Results of an ATL Project
54 | [Dd]ebugPS/
55 | [Rr]eleasePS/
56 | dlldata.c
57 |
58 | # Benchmark Results
59 | BenchmarkDotNet.Artifacts/
60 |
61 | # .NET Core
62 | project.lock.json
63 | project.fragment.lock.json
64 | artifacts/
65 |
66 | # ASP.NET Scaffolding
67 | ScaffoldingReadMe.txt
68 |
69 | # StyleCop
70 | StyleCopReport.xml
71 |
72 | # Files built by Visual Studio
73 | *_i.c
74 | *_p.c
75 | *_h.h
76 | *.ilk
77 | *.meta
78 | *.obj
79 | *.iobj
80 | *.pch
81 | *.pdb
82 | *.ipdb
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio LightSwitch build output
298 | **/*.HTMLClient/GeneratedArtifacts
299 | **/*.DesktopClient/GeneratedArtifacts
300 | **/*.DesktopClient/ModelManifest.xml
301 | **/*.Server/GeneratedArtifacts
302 | **/*.Server/ModelManifest.xml
303 | _Pvt_Extensions
304 |
305 | # Paket dependency manager
306 | .paket/paket.exe
307 | paket-files/
308 |
309 | # FAKE - F# Make
310 | .fake/
311 |
312 | # CodeRush personal settings
313 | .cr/personal
314 |
315 | # Python Tools for Visual Studio (PTVS)
316 | __pycache__/
317 | *.pyc
318 |
319 | # Cake - Uncomment if you are using it
320 | # tools/**
321 | # !tools/packages.config
322 |
323 | # Tabs Studio
324 | *.tss
325 |
326 | # Telerik's JustMock configuration file
327 | *.jmconfig
328 |
329 | # BizTalk build output
330 | *.btp.cs
331 | *.btm.cs
332 | *.odx.cs
333 | *.xsd.cs
334 |
335 | # OpenCover UI analysis results
336 | OpenCover/
337 |
338 | # Azure Stream Analytics local run output
339 | ASALocalRun/
340 |
341 | # MSBuild Binary and Structured Log
342 | *.binlog
343 |
344 | # NVidia Nsight GPU debugger configuration file
345 | *.nvuser
346 |
347 | # MFractors (Xamarin productivity tool) working folder
348 | .mfractor/
349 |
350 | # Local History for Visual Studio
351 | .localhistory/
352 |
353 | # BeatPulse healthcheck temp database
354 | healthchecksdb
355 |
356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
357 | MigrationBackup/
358 |
359 | # Ionide (cross platform F# VS Code tools) working folder
360 | .ionide/
361 |
362 | # Fody - auto-generated XML schema
363 | FodyWeavers.xsd
--------------------------------------------------------------------------------
/MauiTreeView/Controls/TreeViewNode.cs:
--------------------------------------------------------------------------------
1 | //5
2 |
3 | using System.Collections.ObjectModel;
4 | using System.Collections.Specialized;
5 |
6 | namespace MauiTreeView.Controls
7 | {
8 | public class TreeViewNode : StackLayout
9 | {
10 | private DataTemplate _ExpandButtonTemplate = null;
11 |
12 | private TreeViewNode _ParentTreeViewItem;
13 |
14 | private DateTime _ExpandButtonClickedTime;
15 |
16 | private readonly BoxView _SpacerBoxView = new BoxView() { Color = Colors.Transparent };
17 | private readonly BoxView _EmptyBox = new BoxView { BackgroundColor = Colors.Blue, Opacity = .5 };
18 |
19 | private const int ExpandButtonWidth = 32;
20 | private ContentView _ExpandButtonContent = new ();
21 |
22 | private readonly Grid _MainGrid = new Grid
23 | {
24 | VerticalOptions = LayoutOptions.Start,
25 | HorizontalOptions = LayoutOptions.Fill,
26 | RowSpacing = 2
27 | };
28 |
29 | private readonly StackLayout _ContentStackLayout = new StackLayout { Orientation = StackOrientation.Horizontal };
30 |
31 | private readonly ContentView _ContentView = new ContentView
32 | {
33 | HorizontalOptions = LayoutOptions.Fill,
34 | };
35 |
36 | private readonly StackLayout _ChildrenStackLayout = new StackLayout
37 | {
38 | Orientation = StackOrientation.Vertical,
39 | Spacing = 0,
40 | IsVisible = false
41 | };
42 |
43 | private IList _Children = new ObservableCollection();
44 | private readonly TapGestureRecognizer _TapGestureRecognizer = new TapGestureRecognizer();
45 | private readonly TapGestureRecognizer _ExpandButtonGestureRecognizer = new TapGestureRecognizer();
46 | private readonly TapGestureRecognizer _DoubleClickGestureRecognizer = new TapGestureRecognizer();
47 |
48 | internal readonly BoxView SelectionBoxView = new BoxView { Color = Colors.Blue, Opacity = .5, IsVisible = false };
49 |
50 | private TreeView ParentTreeView => Parent?.Parent as TreeView;
51 | private double IndentWidth => Depth * SpacerWidth;
52 | private int SpacerWidth { get; } = 30;
53 | private int Depth => ParentTreeViewItem?.Depth + 1 ?? 0;
54 |
55 | private bool _ShowExpandButtonIfEmpty = false;
56 | private Color _SelectedBackgroundColor = Colors.Blue;
57 | private double _SelectedBackgroundOpacity = .3;
58 |
59 | public event EventHandler Expanded;
60 |
61 | ///
62 | /// Occurs when the user double clicks on the node
63 | ///
64 | public event EventHandler DoubleClicked;
65 |
66 | protected override void OnParentSet()
67 | {
68 | base.OnParentSet();
69 | Render();
70 | }
71 |
72 | public bool IsSelected
73 | {
74 | get => SelectionBoxView.IsVisible;
75 | set => SelectionBoxView.IsVisible = value;
76 | }
77 | public bool IsExpanded
78 | {
79 | get => _ChildrenStackLayout.IsVisible;
80 | set
81 | {
82 | _ChildrenStackLayout.IsVisible = value;
83 |
84 | Render();
85 | if (value)
86 | {
87 | Expanded?.Invoke(this, new EventArgs());
88 | }
89 | }
90 | }
91 |
92 | ///
93 | /// set to true to show the expand button in case we need to poulate the child nodes on demand
94 | ///
95 | public bool ShowExpandButtonIfEmpty
96 | {
97 | get { return _ShowExpandButtonIfEmpty; }
98 | set { _ShowExpandButtonIfEmpty = value; }
99 | }
100 |
101 | ///
102 | /// set BackgroundColor when node is tapped/selected
103 | ///
104 | public Color SelectedBackgroundColor
105 | {
106 | get { return _SelectedBackgroundColor; }
107 | set { _SelectedBackgroundColor = value; }
108 | }
109 |
110 | ///
111 | /// SelectedBackgroundOpacity when node is tapped/selected
112 | ///
113 | public Double SelectedBackgroundOpacity
114 | {
115 | get { return _SelectedBackgroundOpacity; }
116 | set { _SelectedBackgroundOpacity = value; }
117 | }
118 |
119 | ///
120 | /// customize expand icon based on isExpanded property and or data
121 | ///
122 | public DataTemplate ExpandButtonTemplate
123 | {
124 | get { return _ExpandButtonTemplate; }
125 | set { _ExpandButtonTemplate = value; }
126 | }
127 |
128 | public View Content
129 | {
130 | get => _ContentView.Content;
131 | set => _ContentView.Content = value;
132 | }
133 |
134 | public IList ChildrenList
135 | {
136 | get => _Children;
137 | set
138 | {
139 | if (_Children is INotifyCollectionChanged notifyCollectionChanged)
140 | {
141 | notifyCollectionChanged.CollectionChanged -= ItemsSource_CollectionChanged;
142 | }
143 |
144 | _Children = value;
145 |
146 | if (_Children is INotifyCollectionChanged notifyCollectionChanged2)
147 | {
148 | notifyCollectionChanged2.CollectionChanged += ItemsSource_CollectionChanged;
149 | }
150 |
151 | TreeView.RenderNodes(_Children, _ChildrenStackLayout, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset), this);
152 |
153 | Render();
154 | }
155 | }
156 |
157 | ///
158 | /// TODO: Remove this. We should be able to get the ParentTreeViewNode by traversing up through the Visual Tree by 'Parent', but this not working for some reason.
159 | ///
160 | public TreeViewNode ParentTreeViewItem
161 | {
162 | get => _ParentTreeViewItem;
163 | set
164 | {
165 | _ParentTreeViewItem = value;
166 | Render();
167 | }
168 | }
169 |
170 | ///
171 | /// Constructs a new TreeViewItem
172 | ///
173 | public TreeViewNode()
174 | {
175 | var itemsSource = (ObservableCollection)_Children;
176 | itemsSource.CollectionChanged += ItemsSource_CollectionChanged;
177 |
178 | _TapGestureRecognizer.Tapped += TapGestureRecognizer_Tapped;
179 | GestureRecognizers.Add(_TapGestureRecognizer);
180 |
181 | _MainGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
182 | _MainGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
183 | _MainGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
184 |
185 | _MainGrid.Children.Add(SelectionBoxView);
186 |
187 | _ContentStackLayout.Children.Add(_SpacerBoxView);
188 | _ContentStackLayout.Children.Add(_ExpandButtonContent);
189 | _ContentStackLayout.Children.Add(_ContentView);
190 |
191 | SetExpandButtonContent(_ExpandButtonTemplate);
192 |
193 | _ExpandButtonGestureRecognizer.Tapped += ExpandButton_Tapped;
194 | _ExpandButtonContent.GestureRecognizers.Add(_ExpandButtonGestureRecognizer);
195 |
196 | _DoubleClickGestureRecognizer.NumberOfTapsRequired = 2;
197 | _DoubleClickGestureRecognizer.Tapped += DoubleClick;
198 | _ContentView.GestureRecognizers.Add(_DoubleClickGestureRecognizer);
199 |
200 | _MainGrid.SetRow((IView)_ChildrenStackLayout, 1);
201 | _MainGrid.SetColumn((IView)_ChildrenStackLayout, 0);
202 |
203 | _MainGrid.Children.Add(_ContentStackLayout);
204 | _MainGrid.Children.Add(_ChildrenStackLayout);
205 |
206 | base.Children.Add(_MainGrid);
207 |
208 | HorizontalOptions = LayoutOptions.Fill;
209 | VerticalOptions = LayoutOptions.Start;
210 |
211 | Render();
212 | }
213 |
214 | void _DoubleClickGestureRecognizer_Tapped(object sender, EventArgs e)
215 | {
216 | }
217 |
218 | private void ChildSelected(TreeViewNode child)
219 | {
220 | //Um? How does this work? The method here is a private method so how are we calling it?
221 | ParentTreeViewItem?.ChildSelected(child);
222 | ParentTreeView?.ChildSelected(child);
223 | }
224 |
225 | private void Render()
226 | {
227 | _SpacerBoxView.WidthRequest = IndentWidth;
228 |
229 | if ((ChildrenList == null || ChildrenList.Count == 0) && !ShowExpandButtonIfEmpty)
230 | {
231 | SetExpandButtonContent(_ExpandButtonTemplate);
232 | return;
233 | }
234 |
235 | SetExpandButtonContent(_ExpandButtonTemplate);
236 |
237 | foreach (var item in ChildrenList)
238 | {
239 | item.Render();
240 | }
241 | }
242 |
243 | ///
244 | /// Use DataTemplae
245 | ///
246 | private void SetExpandButtonContent(DataTemplate expandButtonTemplate)
247 | {
248 | if (expandButtonTemplate != null)
249 | {
250 | _ExpandButtonContent.Content = (View)expandButtonTemplate.CreateContent();
251 | }
252 | else
253 | {
254 | _ExpandButtonContent.Content = (View)new ContentView { Content = _EmptyBox };
255 | }
256 | }
257 |
258 | private void ExpandButton_Tapped(object sender, EventArgs e)
259 | {
260 | _ExpandButtonClickedTime = DateTime.Now;
261 | IsExpanded = !IsExpanded;
262 | }
263 |
264 | private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
265 | {
266 | //TODO: Hack. We don't want the node to become selected when we are clicking on the expanded button
267 | if (DateTime.Now - _ExpandButtonClickedTime > new TimeSpan(0, 0, 0, 0, 50))
268 | {
269 | ChildSelected(this);
270 | }
271 | }
272 |
273 | private void DoubleClick(object sender, EventArgs e)
274 | {
275 | DoubleClicked?.Invoke(this, new EventArgs());
276 | }
277 |
278 | private void ItemsSource_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
279 | {
280 | TreeView.RenderNodes(_Children, _ChildrenStackLayout, e, this);
281 | Render();
282 | }
283 | }
284 | }
285 |
--------------------------------------------------------------------------------
/MauiTreeView/Resources/Images/dotnet_bot.svg:
--------------------------------------------------------------------------------
1 |
94 |
--------------------------------------------------------------------------------
/MauiTreeView/Resources/Styles/Styles.xaml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
10 |
11 |
15 |
16 |
21 |
22 |
25 |
26 |
47 |
48 |
63 |
64 |
82 |
83 |
102 |
103 |
122 |
123 |
128 |
129 |
147 |
148 |
165 |
166 |
170 |
171 |
191 |
192 |
207 |
208 |
226 |
227 |
230 |
231 |
252 |
253 |
273 |
274 |
280 |
281 |
300 |
301 |
304 |
305 |
333 |
334 |
352 |
353 |
357 |
358 |
370 |
371 |
376 |
377 |
383 |
384 |
385 |
--------------------------------------------------------------------------------