Skip to content

Commit f2c6b03

Browse files
Merge pull request #1 from SyncfusionExamples/Legend_placement_change
TreeMap legend placement change sample added
2 parents 7dc9370 + a2a351b commit f2c6b03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1311
-2
lines changed

README.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,44 @@
1-
# MAUI-TreeMap-legend-placement-change
2-
This repository holds the sample of TreeMap legend placement change in the .NET MAUI platform.
1+
# How to position the legend in .NET MAUI TreeMap (SfTreeMap)
2+
This repository holds a sample of how to change the legend placement in [.NET MAUI TreeMap](https://help.syncfusion.com/maui/treemap/getting-started) control.
3+
4+
Please refer the KB through this [link](https://syncfusion.bolddesk.com/agent/kb/15767)
5+
6+
## Syncfusion Controls
7+
This project used the following Syncfusion control(s):
8+
9+
* [SfTreeMap](https://www.syncfusion.com/maui-controls/maui-tree-map)
10+
11+
## Supported platforms
12+
13+
.NET Multi-platform App UI (.NET MAUI) apps can be written for the following platforms:
14+
* Android 5.0 (API 21) or higher.
15+
* iOS 11 or higher, using the latest release of Xcode.
16+
* macOS 10.15 or higher, using Mac Catalyst.
17+
* Windows 11 and Windows 10 version 1809 or higher, using [Windows UI Library (WinUI) 3](https://learn.microsoft.com/en-us/windows/apps/winui/winui3/).
18+
19+
## How to run the sample
20+
21+
1. Clone the sample and open it in Visual Studio 2022 preview.
22+
23+
*Note: If you download the sample using the "Download ZIP" option, right-click it, select Properties, and then select Unblock.*
24+
25+
2. Register your license key in the App.cs file as demonstrated in the following code.
26+
27+
public App()
28+
{
29+
//Register Syncfusion license
30+
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR LICENSE KEY");
31+
32+
InitializeComponent();
33+
34+
MainPage = new MainPage();
35+
}
36+
37+
Refer to this [link](https://help.syncfusion.com/maui/licensing/overview) for more details.
38+
39+
3. Clean and build the application.
40+
41+
4. Run the application.
42+
43+
## License
44+
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.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34701.34
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TreeMapPositionTheLegend", "TreeMapPositionTheLegend\TreeMapPositionTheLegend.csproj", "{202DD08D-A506-4E25-9037-DFBBF7D18511}"
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+
{202DD08D-A506-4E25-9037-DFBBF7D18511}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{202DD08D-A506-4E25-9037-DFBBF7D18511}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{202DD08D-A506-4E25-9037-DFBBF7D18511}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{202DD08D-A506-4E25-9037-DFBBF7D18511}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{202DD08D-A506-4E25-9037-DFBBF7D18511}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{202DD08D-A506-4E25-9037-DFBBF7D18511}.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 = {864F610C-F599-4CB3-A66F-0FD162C9A3D4}
26+
EndGlobalSection
27+
EndGlobal
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:TreeMapPositionTheLegend"
5+
x:Class="TreeMapPositionTheLegend.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace TreeMapPositionTheLegend
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
10+
}
11+
}
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="TreeMapPositionTheLegend.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:TreeMapPositionTheLegend"
7+
Shell.FlyoutBehavior="Disabled"
8+
Title="TreeMapPositionTheLegend">
9+
10+
<ShellContent
11+
Title="Home"
12+
ContentTemplate="{DataTemplate local:MainPage}"
13+
Route="MainPage" />
14+
15+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace TreeMapPositionTheLegend
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using Syncfusion.Maui.Inputs;
2+
using Syncfusion.Maui.TreeMap;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace TreeMapPositionTheLegend
10+
{
11+
public class LegendPlacementBehaviour : Behavior<ContentPage>
12+
{
13+
#region Fields
14+
15+
/// <summary>
16+
/// The tree map instance.
17+
/// </summary>
18+
private SfTreeMap? treeMap;
19+
20+
/// <summary>
21+
/// The combobox instance
22+
/// </summary>
23+
private SfComboBox? comboBox;
24+
25+
#endregion
26+
27+
#region Override methods
28+
29+
/// <summary>
30+
/// Invoked when behavior is attached to a view.
31+
/// </summary>
32+
/// <param name="sampleView">The sample view to which the behavior is attached.</param>
33+
protected override void OnAttachedTo(ContentPage sampleView)
34+
{
35+
base.OnAttachedTo(sampleView);
36+
this.treeMap = sampleView.FindByName<SfTreeMap>("treeMap");
37+
this.comboBox = sampleView.FindByName<SfComboBox>("comboBox");
38+
if (this.comboBox != null)
39+
{
40+
this.comboBox.SelectionChanged += OnComboBoxSelectionChanged;
41+
}
42+
}
43+
44+
/// <summary>
45+
/// Invoked when behavior is detached from a view.
46+
/// </summary>
47+
/// <param name="sampleView">The sample view from which the behavior is detached.</param>
48+
protected override void OnDetachingFrom(ContentPage sampleView)
49+
{
50+
base.OnDetachingFrom(sampleView);
51+
52+
if (this.treeMap != null)
53+
{
54+
this.treeMap = null;
55+
}
56+
57+
if (this.comboBox != null)
58+
{
59+
this.comboBox.SelectionChanged -= OnComboBoxSelectionChanged;
60+
this.comboBox = null;
61+
}
62+
}
63+
64+
#endregion
65+
66+
#region Property changed
67+
68+
/// <summary>
69+
/// Invokes on combobox selection changed.
70+
/// </summary>
71+
/// <param name="sender">The combobox.</param>
72+
/// <param name="e">The event args.</param>
73+
private void OnComboBoxSelectionChanged(object? sender, Syncfusion.Maui.Inputs.SelectionChangedEventArgs e)
74+
{
75+
if (comboBox.SelectedIndex == 0)
76+
{
77+
treeMap.LegendSettings.Placement = LegendPlacement.Top;
78+
}
79+
80+
else if (comboBox.SelectedIndex == 1)
81+
{
82+
treeMap.LegendSettings.Placement = LegendPlacement.Bottom;
83+
}
84+
}
85+
86+
#endregion
87+
}
88+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:editors="clr-namespace:Syncfusion.Maui.Inputs;assembly=Syncfusion.Maui.Inputs"
5+
xmlns:treemap="clr-namespace:Syncfusion.Maui.TreeMap;assembly=Syncfusion.Maui.TreeMap"
6+
xmlns:local="clr-namespace:TreeMapPositionTheLegend"
7+
x:Class="TreeMapPositionTheLegend.MainPage">
8+
9+
<Grid>
10+
11+
<Grid.RowDefinitions>
12+
<RowDefinition Height="auto" />
13+
<RowDefinition Height="0.85*" />
14+
<RowDefinition Height="0.15*" />
15+
</Grid.RowDefinitions>
16+
17+
<Label Text="American Countries Ordered by Population - 2023"
18+
Grid.Row="0"
19+
VerticalTextAlignment="Center"
20+
HorizontalTextAlignment="Center"
21+
FontSize="14"
22+
Padding="3"
23+
FontAttributes="Bold" />
24+
25+
<editors:SfComboBox x:Name="comboBox"
26+
Grid.Row="2"
27+
HeightRequest="50"
28+
WidthRequest="250"
29+
DisplayMemberPath="PlaceName"
30+
TextMemberPath="PlaceName"
31+
SelectedIndex="0"
32+
ItemsSource="{Binding LegendPlacement}">
33+
<editors:SfComboBox.BindingContext>
34+
<local:LegendPlacementsViewModel />
35+
</editors:SfComboBox.BindingContext>
36+
</editors:SfComboBox>
37+
38+
<treemap:SfTreeMap x:Name="treeMap"
39+
Grid.Row="1"
40+
Margin="8"
41+
DataSource="{Binding PopulationDetails}"
42+
RangeColorValuePath="Population"
43+
PrimaryValuePath="Population">
44+
<treemap:SfTreeMap.BindingContext>
45+
<local:PopulationViewModel />
46+
</treemap:SfTreeMap.BindingContext>
47+
<treemap:SfTreeMap.LegendSettings>
48+
<treemap:TreeMapLegendSettings ShowLegend="True"
49+
Placement="Top" />
50+
</treemap:SfTreeMap.LegendSettings>
51+
<treemap:SfTreeMap.LeafItemSettings>
52+
<treemap:TreeMapLeafItemSettings LabelPath="Country">
53+
</treemap:TreeMapLeafItemSettings>
54+
</treemap:SfTreeMap.LeafItemSettings>
55+
<treemap:SfTreeMap.LeafItemBrushSettings>
56+
<treemap:TreeMapRangeBrushSettings>
57+
<treemap:TreeMapRangeBrushSettings.RangeBrushes>
58+
<treemap:TreeMapRangeBrush LegendLabel="50M - 1B"
59+
From="50000000"
60+
To="1000000000"
61+
Brush="#3F8D71" />
62+
<treemap:TreeMapRangeBrush LegendLabel="10M - 50M"
63+
From="10000000"
64+
To="50000000"
65+
Brush="#5BA985" />
66+
<treemap:TreeMapRangeBrush LegendLabel="0.1M - 10M"
67+
From="100000"
68+
To="10000000"
69+
Brush="#7DC59D" />
70+
</treemap:TreeMapRangeBrushSettings.RangeBrushes>
71+
</treemap:TreeMapRangeBrushSettings>
72+
</treemap:SfTreeMap.LeafItemBrushSettings>
73+
</treemap:SfTreeMap>
74+
75+
</Grid>
76+
77+
<ContentPage.Behaviors>
78+
<local:LegendPlacementBehaviour />
79+
</ContentPage.Behaviors>
80+
81+
</ContentPage>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace TreeMapPositionTheLegend
2+
{
3+
public partial class MainPage : ContentPage
4+
{
5+
public MainPage()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.Extensions.Logging;
2+
using Syncfusion.Maui.Core.Hosting;
3+
4+
namespace TreeMapPositionTheLegend
5+
{
6+
public static class MauiProgram
7+
{
8+
public static MauiApp CreateMauiApp()
9+
{
10+
var builder = MauiApp.CreateBuilder();
11+
builder
12+
.ConfigureSyncfusionCore()
13+
.UseMauiApp<App>()
14+
.ConfigureFonts(fonts =>
15+
{
16+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
17+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
18+
});
19+
20+
#if DEBUG
21+
builder.Logging.AddDebug();
22+
#endif
23+
24+
return builder.Build();
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)