Skip to content

Commit 2a09291

Browse files
Customize list view using different templates
1 parent 6b03356 commit 2a09291

Some content is hidden

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

61 files changed

+1292
-0
lines changed

Appearance_MAUI_ListView/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:Appearance_MAUI_ListView"
5+
x:Class="Appearance_MAUI_ListView.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 Appearance_MAUI_ListView;
2+
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
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="Appearance_MAUI_ListView.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:Appearance_MAUI_ListView"
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 Appearance_MAUI_ListView;
2+
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.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);net7.0-tizen</TargetFrameworks> -->
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>Appearance_MAUI_ListView</RootNamespace>
10+
<UseMaui>true</UseMaui>
11+
<SingleProject>true</SingleProject>
12+
<ImplicitUsings>enable</ImplicitUsings>
13+
14+
<!-- Display name -->
15+
<ApplicationTitle>Appearance_MAUI_ListView</ApplicationTitle>
16+
17+
<!-- App Identifier -->
18+
<ApplicationId>com.companyname.appearance_maui_listview</ApplicationId>
19+
<ApplicationIdGuid>58c361b7-fb63-4e39-bf93-87f9ff9cac84</ApplicationIdGuid>
20+
21+
<!-- Versions -->
22+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
23+
<ApplicationVersion>1</ApplicationVersion>
24+
25+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
26+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</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+
<None Remove="Resources\Images\Image0.png" />
53+
<None Remove="Resources\Images\Image1.png" />
54+
<None Remove="Resources\Images\Image10.png" />
55+
<None Remove="Resources\Images\Image11.png" />
56+
<None Remove="Resources\Images\Image12.png" />
57+
<None Remove="Resources\Images\Image13.png" />
58+
<None Remove="Resources\Images\Image14.png" />
59+
<None Remove="Resources\Images\Image15.png" />
60+
<None Remove="Resources\Images\Image16.png" />
61+
<None Remove="Resources\Images\Image17.png" />
62+
<None Remove="Resources\Images\Image18.png" />
63+
<None Remove="Resources\Images\Image19.png" />
64+
<None Remove="Resources\Images\Image2.png" />
65+
<None Remove="Resources\Images\Image3.png" />
66+
<None Remove="Resources\Images\Image4.png" />
67+
<None Remove="Resources\Images\Image5.png" />
68+
<None Remove="Resources\Images\Image6.png" />
69+
<None Remove="Resources\Images\Image7.png" />
70+
<None Remove="Resources\Images\Image8.png" />
71+
<None Remove="Resources\Images\Image9.png" />
72+
</ItemGroup>
73+
74+
<ItemGroup>
75+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
76+
<PackageReference Include="Syncfusion.Maui.ListView" Version="20.4.54" />
77+
</ItemGroup>
78+
79+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
5+
<ActiveDebugFramework>net7.0-android</ActiveDebugFramework>
6+
<ActiveDebugProfile>Pixel 5 - API 32 (Android 12.1 - API 32)</ActiveDebugProfile>
7+
<SelectedPlatformGroup>Emulator</SelectedPlatformGroup>
8+
<DefaultDevice>pixel_5_-_api_32</DefaultDevice>
9+
</PropertyGroup>
10+
</Project>
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}") = "Appearance_MAUI_ListView", "Appearance_MAUI_ListView.csproj", "{58CD4537-2E82-48DD-A23E-26E3406CB764}"
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+
{58CD4537-2E82-48DD-A23E-26E3406CB764}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{58CD4537-2E82-48DD-A23E-26E3406CB764}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{58CD4537-2E82-48DD-A23E-26E3406CB764}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{58CD4537-2E82-48DD-A23E-26E3406CB764}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{58CD4537-2E82-48DD-A23E-26E3406CB764}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{58CD4537-2E82-48DD-A23E-26E3406CB764}.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
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 Appearance_MAUI_ListView
9+
{
10+
internal class ContactInfo: INotifyPropertyChanged
11+
{
12+
public string ContactName { get; set; }
13+
public string ContactImage { get; set; }
14+
public string ContactNumber { get; set; }
15+
public bool IsMissed { get; set; }
16+
17+
private bool isExpanded = false;
18+
public bool IsExpanded
19+
{
20+
get { return isExpanded; }
21+
set
22+
{
23+
isExpanded = value;
24+
this.RaisedOnPropertyChanged("IsExpanded");
25+
}
26+
}
27+
28+
public event PropertyChangedEventHandler PropertyChanged;
29+
30+
public void RaisedOnPropertyChanged(string _PropertyName)
31+
{
32+
if (PropertyChanged != null)
33+
{
34+
PropertyChanged(this, new PropertyChangedEventArgs(_PropertyName));
35+
}
36+
}
37+
}
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Syncfusion.Maui.ListView;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Appearance_MAUI_ListView
10+
{
11+
internal class ContactInfoDataTemplateSelector : DataTemplateSelector
12+
{
13+
public DataTemplate NormalTemplate { get; set; }
14+
public DataTemplate MissedCallTemplate { get; set; }
15+
16+
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
17+
{
18+
var contact = (ContactInfo)item;
19+
if(contact != null)
20+
{
21+
if (contact.IsMissed)
22+
return MissedCallTemplate;
23+
else
24+
return NormalTemplate;
25+
}
26+
27+
return NormalTemplate;
28+
}
29+
}
30+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Appearance_MAUI_ListView
9+
{
10+
internal class ContactInfoRepo
11+
{
12+
public ObservableCollection<ContactInfo> Contacts { get; set; }
13+
14+
public ContactInfoRepo()
15+
{
16+
Contacts = GetContactDetails(20);
17+
}
18+
19+
public ObservableCollection<ContactInfo> GetContactDetails(int count)
20+
{
21+
var contacts = new ObservableCollection<ContactInfo>();
22+
Random random = new Random();
23+
24+
for(int i=0; i<count; i++)
25+
{
26+
var contact = new ContactInfo()
27+
{
28+
ContactName = CustomerNames[i],
29+
ContactImage = "image"+ i.ToString() + ".png",
30+
ContactNumber = random.Next(100, 400).ToString() + "-" + random.Next(500, 800).ToString() + "-" + random.Next(1000, 2000).ToString(),
31+
};
32+
if (i % 3 == 0 || i % 5 == 0)
33+
{
34+
contact.IsMissed = true;
35+
}
36+
contacts.Add(contact);
37+
}
38+
39+
return contacts;
40+
}
41+
42+
string[] CustomerNames = new string[]
43+
{
44+
"Kyle",
45+
"Gina",
46+
"Liz",
47+
"Larry",
48+
"Katie",
49+
"Liam",
50+
"Irene",
51+
"Michael",
52+
"Oscar",
53+
"Ralph",
54+
"Torrey",
55+
"William",
56+
"Bill",
57+
"Daniel",
58+
"Frank",
59+
"Brenda",
60+
"Danielle",
61+
"Fiona",
62+
"Howard",
63+
"Jack",
64+
};
65+
}
66+
}

0 commit comments

Comments
 (0)