Skip to content

Commit 203361f

Browse files
Merge pull request #1 from SyncfusionExamples/ListView-customization
Prepared the ListView customization sample
2 parents eb3632e + b05b91e commit 203361f

40 files changed

+1260
-1
lines changed

ListViewSample/ListViewSample.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.11.35208.52
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ListViewSample", "ListViewSample\ListViewSample.csproj", "{AEB65A45-56DC-4865-A589-6799F91504C4}"
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+
{AEB65A45-56DC-4865-A589-6799F91504C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{AEB65A45-56DC-4865-A589-6799F91504C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{AEB65A45-56DC-4865-A589-6799F91504C4}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{AEB65A45-56DC-4865-A589-6799F91504C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{AEB65A45-56DC-4865-A589-6799F91504C4}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{AEB65A45-56DC-4865-A589-6799F91504C4}.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 = {BC7F2901-4A6E-4EA6-95B7-AF43A485BDAA}
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:ListViewSample"
5+
x:Class="ListViewSample.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 ListViewSample
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
10+
}
11+
}
12+
}
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="ListViewSample.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:ListViewSample"
7+
Shell.FlyoutBehavior="Disabled"
8+
Title="ListViewSample">
9+
10+
<ShellContent
11+
ContentTemplate="{DataTemplate local:MainPage}"
12+
Route="MainPage" />
13+
14+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace ListViewSample
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
6+
namespace ListViewSample
7+
{
8+
public class BookInfo
9+
{
10+
public string Name { get; set; }
11+
12+
public string Description { get; set; }
13+
}
14+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.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);net8.0-tizen</TargetFrameworks> -->
8+
9+
<!-- Note for MacCatalyst:
10+
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
11+
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
12+
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
13+
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
14+
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
15+
16+
<OutputType>Exe</OutputType>
17+
<RootNamespace>ListViewSample</RootNamespace>
18+
<UseMaui>true</UseMaui>
19+
<SingleProject>true</SingleProject>
20+
<ImplicitUsings>enable</ImplicitUsings>
21+
<Nullable>enable</Nullable>
22+
23+
<!-- Display name -->
24+
<ApplicationTitle>ListViewSample</ApplicationTitle>
25+
26+
<!-- App Identifier -->
27+
<ApplicationId>com.companyname.listviewsample</ApplicationId>
28+
29+
<!-- Versions -->
30+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
31+
<ApplicationVersion>1</ApplicationVersion>
32+
33+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
34+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
35+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
36+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
37+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
38+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
39+
</PropertyGroup>
40+
41+
<ItemGroup>
42+
<!-- App Icon -->
43+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
44+
45+
<!-- Splash Screen -->
46+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
47+
48+
<!-- Images -->
49+
<MauiImage Include="Resources\Images\*" />
50+
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />
51+
52+
<!-- Custom Fonts -->
53+
<MauiFont Include="Resources\Fonts\*" />
54+
55+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
56+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
57+
</ItemGroup>
58+
59+
<ItemGroup>
60+
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.80" />
61+
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.80" />
62+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
63+
<PackageReference Include="Syncfusion.Maui.ListView" Version="*" />
64+
</ItemGroup>
65+
66+
</Project>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ListViewSample
8+
{
9+
public class LoadMoreViewModel
10+
{
11+
private readonly int totalItems = 15;
12+
public ObservableCollection<BookInfo> BookDetails { get; set; }
13+
public Command<object> LoadMoreItemsCommand { get; set; }
14+
15+
public LoadMoreViewModel()
16+
{
17+
BookDetails = new ObservableCollection<BookInfo>();
18+
GenerateSource(5);
19+
LoadMoreItemsCommand = new Command<object>(LoadMoreItems,CanLoadMoreItems);
20+
}
21+
22+
private bool CanLoadMoreItems(object obj)
23+
{
24+
if(BookDetails.Count >= totalItems)
25+
{
26+
return false;
27+
}
28+
return true;
29+
}
30+
31+
private async void LoadMoreItems(object obj)
32+
{
33+
var listView = obj as Syncfusion.Maui.ListView.SfListView;
34+
if(listView != null )
35+
{
36+
listView.IsLazyLoading = true;
37+
await Task.Delay(2500);
38+
var index = BookDetails.Count;
39+
var count = index + 2 >= totalItems ? totalItems - index : 2;
40+
for (int i = index; i < index + count; i++)
41+
{
42+
var books = new BookInfo()
43+
{
44+
Name = BookNames[i],
45+
Description = BookDescriptions[i]
46+
};
47+
BookDetails.Add(books);
48+
}
49+
listView.IsLazyLoading = false;
50+
}
51+
}
52+
53+
private void GenerateSource(int value)
54+
{
55+
for (int i = 0; i < value; i++)
56+
{
57+
var book = new BookInfo()
58+
{
59+
Name = BookNames[i],
60+
Description = BookDescriptions[i]
61+
};
62+
63+
BookDetails.Add(book);
64+
}
65+
}
66+
67+
private readonly string[] BookNames = new string[]
68+
{
69+
"Object-Oriented Programming in C#",
70+
"C# Code Contracts",
71+
"Machine Learning Using C#",
72+
"Neural Networks Using C#",
73+
"Visual Studio Code",
74+
"Android Programming",
75+
"iOS Succinctly",
76+
"Visual Studio 2015",
77+
"Xamarin.Forms",
78+
"Windows Store Apps",
79+
"Agile Software Development",
80+
"Assembly Language",
81+
"Cryptography in .NET",
82+
"Entity Framework Code First",
83+
"Localization for .NET"
84+
};
85+
86+
private readonly string[] BookDescriptions = new string[]
87+
{
88+
"Object-oriented programming is the de facto programming paradigm.",
89+
"Code Contracts provide a way to convey code assumptions.",
90+
"You’ll learn several different approaches to applying machine learning.",
91+
"Neural networks are an exciting field of software development.",
92+
"It is a powerful tool for editing code and serves for end-to-end programming.",
93+
"It is provides a useful overview of the Android application lifecycle.",
94+
"It is for developers looking to step into frightening world of iPhone.",
95+
"The new version of the widely-used integrated development environment.",
96+
"Its creates mappings from its C# classes and controls directly.",
97+
"Windows Store apps present a radical shift in Windows development.",
98+
"Learning new development processes can be difficult.",
99+
"Assembly language is as close to writing machine code.",
100+
"Cryptography is used throughout software to protect all kinds of information.",
101+
"Follow author Ricardo Peres as he introduces the newest development mode.",
102+
"Learn to write applications that support different languages and cultures."
103+
};
104+
}
105+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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:listview="clr-namespace:Syncfusion.Maui.ListView;assembly=Syncfusion.Maui.ListView"
5+
xmlns:local="clr-namespace:ListViewSample"
6+
x:Class="ListViewSample.MainPage">
7+
8+
<ContentPage.BindingContext>
9+
<local:LoadMoreViewModel/>
10+
</ContentPage.BindingContext>
11+
12+
<listview:SfListView x:Name="listView" ItemSize="100" ItemsSource="{Binding BookDetails}"
13+
LoadMoreCommand="{Binding LoadMoreItemsCommand}"
14+
LoadMoreOption="Manual"
15+
LoadMoreCommandParameter="{Binding Source={x:Reference listView}}"
16+
LoadMorePosition="End">
17+
<listview:SfListView.LoadMoreTemplate>
18+
<DataTemplate>
19+
<Grid HeightRequest="30" WidthRequest="200" Background="Purple">
20+
<Label Text="Show more..." TextColor="LightCyan"
21+
FontSize="20" FontAttributes="Bold"
22+
HorizontalTextAlignment="Center"
23+
VerticalTextAlignment="Center"/>
24+
</Grid>
25+
</DataTemplate>
26+
</listview:SfListView.LoadMoreTemplate>
27+
<listview:SfListView.ItemTemplate>
28+
<DataTemplate>
29+
<Grid Padding="5">
30+
<Grid.RowDefinitions>
31+
<RowDefinition Height="0.4*"/>
32+
<RowDefinition Height="0.9*"/>
33+
</Grid.RowDefinitions>
34+
<Label x:Name="name" Text="{Binding Name}" Grid.Row="0" FontSize="17" FontAttributes="Bold"/>
35+
<Label x:Name="description" Text="{Binding Description}" Grid.Row="1" FontSize="15" />
36+
</Grid>
37+
</DataTemplate>
38+
</listview:SfListView.ItemTemplate>
39+
</listview:SfListView>
40+
41+
</ContentPage>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace ListViewSample
2+
{
3+
public partial class MainPage : ContentPage
4+
{
5+
6+
public MainPage()
7+
{
8+
InitializeComponent();
9+
}
10+
11+
12+
}
13+
14+
}

0 commit comments

Comments
 (0)