Skip to content

Commit 7c4f49f

Browse files
Merge pull request #1 from SujaVenkatesan/sample
MAUI-4054 : How to sort the items by datetime property along with Grouping in .Net Maui (SfListview)
2 parents 63b211b + 5cb4972 commit 7c4f49f

39 files changed

+1305
-0
lines changed

ListViewMaui/ListViewMaui.sln

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.0.31611.283
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ListViewMaui", "ListViewMaui\ListViewMaui.csproj", "{02F7D986-E626-42A6-A9A1-B36C96C4290B}"
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+
{02F7D986-E626-42A6-A9A1-B36C96C4290B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{02F7D986-E626-42A6-A9A1-B36C96C4290B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{02F7D986-E626-42A6-A9A1-B36C96C4290B}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{02F7D986-E626-42A6-A9A1-B36C96C4290B}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{02F7D986-E626-42A6-A9A1-B36C96C4290B}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{02F7D986-E626-42A6-A9A1-B36C96C4290B}.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

ListViewMaui/ListViewMaui/App.xaml

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:ListViewMaui"
5+
x:Class="ListViewMaui.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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace ListViewMaui;
2+
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new MainPage();
10+
}
11+
}
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+
<Shell
3+
x:Class="ListViewMaui.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:ListViewMaui"
7+
Shell.FlyoutBehavior="Disabled">
8+
9+
<ShellContent
10+
Title="Home"
11+
ContentTemplate="{DataTemplate local:MainPage}"
12+
Route="MainPage" />
13+
14+
</Shell>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ListViewMaui;
2+
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using ListViewMaui.Helper;
2+
using Microsoft.Maui.Controls;
3+
using Syncfusion.Maui.DataSource;
4+
using Syncfusion.Maui.DataSource.Extensions;
5+
using Syncfusion.Maui.ListView;
6+
using Syncfusion.Maui.ListView.Helpers;
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Linq;
10+
using System.Reflection;
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
14+
namespace ListViewMaui
15+
{
16+
public class Behavior:Behavior<ContentPage>
17+
{
18+
#region Fields
19+
20+
private Syncfusion.Maui.ListView.SfListView listView;
21+
22+
#endregion
23+
24+
#region Overrides
25+
protected override void OnAttachedTo(ContentPage bindable)
26+
{
27+
listView = bindable.FindByName<Syncfusion.Maui.ListView.SfListView>("listView");
28+
listView.DataSource.GroupDescriptors.Add(new GroupDescriptor()
29+
{
30+
PropertyName = "DateOfBirth",
31+
KeySelector = (object obj1) =>
32+
{
33+
var item = (obj1 as Contacts);
34+
return item.DateOfBirth.Year;
35+
},
36+
});
37+
38+
this.listView.DataSource.SortDescriptors.Add(new SortDescriptor()
39+
{
40+
PropertyName = "DateOfBirth",
41+
Direction = ListSortDirection.Ascending
42+
});
43+
base.OnAttachedTo(bindable);
44+
}
45+
protected override void OnDetachingFrom(ContentPage bindable)
46+
{
47+
listView = null;
48+
base.OnDetachingFrom(bindable);
49+
}
50+
#endregion
51+
}
52+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Syncfusion.Maui.DataSource.Extensions;
2+
using Syncfusion.Maui.DataSource;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace ListViewMaui.Helper
10+
{
11+
class CustomGroupComparer : IComparer<GroupResult>, ISortDirection
12+
{
13+
public CustomGroupComparer()
14+
{
15+
this.SortDirection = ListSortDirection.Ascending;
16+
}
17+
18+
public ListSortDirection SortDirection
19+
{
20+
get;
21+
set;
22+
}
23+
24+
public int Compare(GroupResult x, GroupResult y)
25+
{
26+
DateTime xvalue = Convert.ToDateTime(x.Key);
27+
DateTime yvalue = Convert.ToDateTime(y.Key);
28+
29+
// Group results are compared and return the SortDirection
30+
if (xvalue.CompareTo(yvalue) > 0)
31+
return SortDirection == ListSortDirection.Ascending ? 1 : -1;
32+
else if (xvalue.CompareTo(yvalue) == -1)
33+
return SortDirection == ListSortDirection.Ascending ? -1 : 1;
34+
else
35+
return 0;
36+
}
37+
}
38+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
6+
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
7+
<!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>ListViewMaui</RootNamespace>
10+
<UseMaui>true</UseMaui>
11+
<SingleProject>true</SingleProject>
12+
<ImplicitUsings>enable</ImplicitUsings>
13+
14+
<!-- Display name -->
15+
<ApplicationTitle>ListViewMaui</ApplicationTitle>
16+
17+
<!-- App Identifier -->
18+
<ApplicationId>com.companyname.listviewmaui</ApplicationId>
19+
<ApplicationIdGuid>056ca992-8c2e-48d1-8b06-7eace6d8c73d</ApplicationIdGuid>
20+
21+
<!-- Versions -->
22+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
23+
<ApplicationVersion>1</ApplicationVersion>
24+
25+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
26+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
27+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
28+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
29+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
30+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
31+
</PropertyGroup>
32+
33+
<ItemGroup>
34+
<!-- App Icon -->
35+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
36+
37+
<!-- Splash Screen -->
38+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
39+
40+
<!-- Images -->
41+
<MauiImage Include="Resources\Images\*" />
42+
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
43+
44+
<!-- Custom Fonts -->
45+
<MauiFont Include="Resources\Fonts\*" />
46+
47+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
48+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
49+
</ItemGroup>
50+
51+
<ItemGroup>
52+
<PackageReference Include="Syncfusion.Maui.ListView" Version="*" />
53+
</ItemGroup>
54+
55+
<ItemGroup>
56+
<Compile Update="View\MainPage.xaml.cs">
57+
<DependentUpon>%(Filename)</DependentUpon>
58+
</Compile>
59+
</ItemGroup>
60+
61+
<ItemGroup>
62+
<MauiXaml Update="View\MainPage.xaml">
63+
<Generator>MSBuild:Compile</Generator>
64+
</MauiXaml>
65+
</ItemGroup>
66+
67+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Syncfusion.Maui.Core.Hosting;
2+
namespace ListViewMaui;
3+
4+
public static class MauiProgram
5+
{
6+
public static MauiApp CreateMauiApp()
7+
{
8+
var builder = MauiApp.CreateBuilder();
9+
builder
10+
.UseMauiApp<App>()
11+
.ConfigureFonts(fonts =>
12+
{
13+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
14+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
15+
});
16+
builder.ConfigureSyncfusionCore();
17+
return builder.Build();
18+
}
19+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace ListViewMaui
9+
{
10+
11+
public class Contacts : INotifyPropertyChanged
12+
{
13+
private string contactName;
14+
private DateTimeOffset dateOfBirth;
15+
16+
public Contacts(string name, DateTimeOffset number)
17+
{
18+
contactName = name;
19+
dateOfBirth = number;
20+
}
21+
public Contacts()
22+
{
23+
24+
}
25+
public string ContactName
26+
{
27+
get { return contactName; }
28+
set
29+
{
30+
if (contactName != value)
31+
{
32+
contactName = value;
33+
this.RaisedOnPropertyChanged("ContactName");
34+
}
35+
}
36+
}
37+
public DateTimeOffset DateOfBirth
38+
{
39+
get { return dateOfBirth; }
40+
set
41+
{
42+
if (dateOfBirth != value)
43+
{
44+
dateOfBirth = value;
45+
this.RaisedOnPropertyChanged("DateOfBirth");
46+
}
47+
}
48+
}
49+
50+
public event PropertyChangedEventHandler PropertyChanged;
51+
52+
public void RaisedOnPropertyChanged(string _PropertyName)
53+
{
54+
if (PropertyChanged != null)
55+
{
56+
PropertyChanged(this, new PropertyChangedEventArgs(_PropertyName));
57+
}
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)