Skip to content

Commit c091f48

Browse files
Sample added
1 parent 1655927 commit c091f48

40 files changed

+1306
-0
lines changed

AutocompleteSample.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36203.30 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutocompleteSample", "AutocompleteSample\AutocompleteSample.csproj", "{A2EB69E4-5E6F-4CB0-8EB1-061E65869224}"
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+
{A2EB69E4-5E6F-4CB0-8EB1-061E65869224}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{A2EB69E4-5E6F-4CB0-8EB1-061E65869224}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{A2EB69E4-5E6F-4CB0-8EB1-061E65869224}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{A2EB69E4-5E6F-4CB0-8EB1-061E65869224}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {8D25F2E2-B0D0-4754-9EBF-A116E660667F}
24+
EndGlobalSection
25+
EndGlobal

AutocompleteSample/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:AutocompleteSample"
5+
x:Class="AutocompleteSample.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>

AutocompleteSample/App.xaml.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace AutocompleteSample
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
protected override Window CreateWindow(IActivationState? activationState)
11+
{
12+
return new Window(new AppShell());
13+
}
14+
}
15+
}

AutocompleteSample/AppShell.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+
<Shell
3+
x:Class="AutocompleteSample.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:AutocompleteSample"
7+
Title="AutocompleteSample">
8+
9+
<ShellContent
10+
Title="Home"
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 AutocompleteSample
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.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);net9.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>AutocompleteSample</RootNamespace>
18+
<UseMaui>true</UseMaui>
19+
<SingleProject>true</SingleProject>
20+
<ImplicitUsings>enable</ImplicitUsings>
21+
<Nullable>enable</Nullable>
22+
23+
<!-- Display name -->
24+
<ApplicationTitle>AutocompleteSample</ApplicationTitle>
25+
26+
<!-- App Identifier -->
27+
<ApplicationId>com.companyname.autocompletesample</ApplicationId>
28+
29+
<!-- Versions -->
30+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
31+
<ApplicationVersion>1</ApplicationVersion>
32+
33+
<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
34+
<WindowsPackageType>None</WindowsPackageType>
35+
36+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
37+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
38+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
39+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
40+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
41+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
42+
</PropertyGroup>
43+
44+
<ItemGroup>
45+
<!-- App Icon -->
46+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
47+
48+
<!-- Splash Screen -->
49+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
50+
51+
<!-- Images -->
52+
<MauiImage Include="Resources\Images\*" />
53+
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />
54+
55+
<!-- Custom Fonts -->
56+
<MauiFont Include="Resources\Fonts\*" />
57+
58+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
59+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
60+
</ItemGroup>
61+
62+
<ItemGroup>
63+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
64+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
65+
<PackageReference Include="Syncfusion.Maui.Inputs" Version="*" />
66+
</ItemGroup>
67+
68+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.5.2.0
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutocompleteSample", "AutocompleteSample.csproj", "{D0746B92-8422-4226-1D44-2A06039D16B2}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{D0746B92-8422-4226-1D44-2A06039D16B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{D0746B92-8422-4226-1D44-2A06039D16B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{D0746B92-8422-4226-1D44-2A06039D16B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{D0746B92-8422-4226-1D44-2A06039D16B2}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {5247DB8F-1944-4F6F-9571-F12977E52365}
23+
EndGlobalSection
24+
EndGlobal
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using AutocompleteSample.ViewModel;
2+
using Syncfusion.Maui.Inputs;
3+
using System;
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Text.Json;
9+
using System.Threading.Tasks;
10+
11+
namespace AutocompleteSample.CustomFilter
12+
{
13+
public class AutocompleteCustomFilter : IAutocompleteFilterBehavior
14+
{
15+
private CancellationTokenSource? _cts;
16+
17+
public async Task<object?> GetMatchingItemsAsync(SfAutocomplete autocomplete, AutocompleteFilterInfo filterInfo)
18+
{
19+
// Cancel any ongoing request
20+
_cts?.Cancel();
21+
_cts?.Dispose();
22+
_cts = new CancellationTokenSource();
23+
var cancellationToken = _cts.Token;
24+
25+
if (autocomplete != null)
26+
{
27+
var text = filterInfo.Text ?? string.Empty;
28+
using (HttpClient client = new HttpClient())
29+
{
30+
string filter = $"$filter=startswith(ContactName, '{text}') or startswith(ContactTitle, '{text}') or startswith(Country, '{text}')";
31+
string requestUrl = $"https://services.odata.org/V4/Northwind/Northwind.svc/Customers?{filter}&$format=json";
32+
try
33+
{
34+
HttpResponseMessage response = await client.GetAsync(requestUrl, cancellationToken);
35+
response.EnsureSuccessStatusCode();
36+
37+
string jsonResponse = await response.Content.ReadAsStringAsync(cancellationToken);
38+
39+
var odataResponse = JsonSerializer.Deserialize<ODataResponse<Customer>>(jsonResponse);
40+
41+
List<Customer> customers = odataResponse?.value?.Take(5).ToList() ?? new List<Customer>();
42+
return customers;
43+
}
44+
catch (OperationCanceledException)
45+
{
46+
// Request was cancelled, return empty list
47+
return new List<Customer>();
48+
}
49+
catch (Exception ex)
50+
{
51+
return new List<Customer>();
52+
}
53+
}
54+
}
55+
return new List<Customer>();
56+
}
57+
}
58+
}

AutocompleteSample/MainPage.xaml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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:filter="clr-namespace:AutocompleteSample.CustomFilter"
5+
xmlns:vm="clr-namespace:AutocompleteSample.ViewModel"
6+
xmlns:editors="clr-namespace:Syncfusion.Maui.Inputs;assembly=Syncfusion.Maui.Inputs"
7+
xmlns:inputlayout="clr-namespace:Syncfusion.Maui.Core;assembly=Syncfusion.Maui.Core"
8+
x:Class="AutocompleteSample.MainPage">
9+
10+
<ContentPage.BindingContext>
11+
<vm:CustomerViewModel/>
12+
</ContentPage.BindingContext>
13+
14+
<ScrollView>
15+
<VerticalStackLayout
16+
Padding="30,0"
17+
Spacing="25">
18+
<inputlayout:SfTextInputLayout ContainerType="Outlined"
19+
ShowHint="False"
20+
ReserveSpaceForAssistiveLabels="False"
21+
Padding="0,-2,0,0"
22+
OutlineCornerRadius="8"
23+
IsHintAlwaysFloated="True"
24+
WidthRequest="360"
25+
HeightRequest="60">
26+
<editors:SfAutocomplete x:Name="autocomplete"
27+
VerticalOptions="Start"
28+
NoResultsFoundText=""
29+
DropDownBackground="WhiteSmoke"
30+
DropDownStroke="Black"
31+
DropDownItemHeight="54"
32+
PlaceholderColor="#283618"
33+
ShowBorder="False"
34+
ClearButtonIconColor="#283618"
35+
TextSearchMode="Contains"
36+
Placeholder="Search by Customer Name/Designation/Country"
37+
DisplayMemberPath="ContactName"
38+
ItemsSource="{Binding CustomerDetails}">
39+
<editors:SfAutocomplete.FilterBehavior>
40+
<filter:AutocompleteCustomFilter/>
41+
</editors:SfAutocomplete.FilterBehavior>
42+
<editors:SfAutocomplete.ItemTemplate>
43+
<DataTemplate>
44+
<Grid Padding="10" RowDefinitions="Auto,Auto">
45+
<HorizontalStackLayout Grid.Row="0"
46+
Spacing="2">
47+
<Label
48+
Text="{Binding ContactName}"
49+
FontAttributes="Bold"
50+
VerticalOptions="Center"
51+
FontSize="16"
52+
TextColor="Black"/>
53+
<Label Text=" - "
54+
VerticalOptions="Center"
55+
FontSize="12"/>
56+
<Label VerticalOptions="Center"
57+
Text="{Binding ContactTitle}"
58+
FontAttributes="Bold"
59+
FontSize="12"
60+
TextColor="Black"/>
61+
<Label Text="&#xe78c;"
62+
VerticalOptions="Center"
63+
FontSize="14"
64+
Padding="4,0"
65+
TextColor="#50D072"
66+
FontFamily="MauiMaterialAssets"/>
67+
</HorizontalStackLayout>
68+
<HorizontalStackLayout Grid.Row="1"
69+
Spacing="2">
70+
<Label Text="&#xe71c;"
71+
VerticalOptions="Center"
72+
FontSize="14"
73+
Padding="4,0"
74+
TextColor="Green"
75+
FontFamily="MauiMaterialAssets"/>
76+
<Label
77+
Text="{Binding City}"
78+
FontSize="12"
79+
VerticalOptions="Center"/>
80+
<Label Text=", "
81+
VerticalOptions="Center"
82+
FontSize="12"/>
83+
<Label VerticalOptions="Center"
84+
Text="{Binding Country}"
85+
FontSize="12"
86+
TextColor="Black"/>
87+
</HorizontalStackLayout>
88+
</Grid>
89+
</DataTemplate>
90+
</editors:SfAutocomplete.ItemTemplate>
91+
</editors:SfAutocomplete>
92+
</inputlayout:SfTextInputLayout>
93+
</VerticalStackLayout>
94+
</ScrollView>
95+
96+
</ContentPage>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace AutocompleteSample
2+
{
3+
public partial class MainPage : ContentPage
4+
{
5+
int count = 0;
6+
7+
public MainPage()
8+
{
9+
InitializeComponent();
10+
}
11+
12+
13+
}
14+
}

0 commit comments

Comments
 (0)