Skip to content

Commit d17c9cc

Browse files
Sample added for contact form
1 parent e5662d9 commit d17c9cc

Some content is hidden

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

72 files changed

+1794
-0
lines changed

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

DataFormMAUI/App.xaml.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace DataFormMAUI;
2+
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new NavigationPage(new MainPage());
10+
11+
}
12+
13+
static SQLiteDatabase database;
14+
15+
// Create the database connection as a singleton.
16+
public static SQLiteDatabase Database
17+
{
18+
get
19+
{
20+
if (database == null)
21+
{
22+
database = new SQLiteDatabase();
23+
}
24+
return database;
25+
}
26+
}
27+
//protected override Window CreateWindow(IActivationState activationState)
28+
//{
29+
// var window = base.CreateWindow(activationState);
30+
// window.Width = 500;
31+
// window.Height = 00;
32+
// return window;
33+
//}
34+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
using Syncfusion.Maui.DataForm;
2+
3+
namespace DataFormMAUI
4+
{
5+
6+
/// <summary>
7+
/// Represents a behavior class for contact form.
8+
/// </summary>
9+
public class ContactFormBehavior : Behavior<ContentPage>
10+
{
11+
/// <summary>
12+
/// Holds the data form object.
13+
/// </summary>
14+
private SfDataForm? dataForm;
15+
16+
/// <summary>
17+
/// Holds the save button instance.
18+
/// </summary>
19+
private Button? saveButton;
20+
21+
/// <inheritdoc/>
22+
protected override void OnAttachedTo(ContentPage bindable)
23+
{
24+
base.OnAttachedTo(bindable);
25+
this.dataForm = bindable.FindByName<SfDataForm>("contactForm");
26+
27+
if (this.dataForm != null)
28+
{
29+
dataForm.ValidateForm += this.OnDataFormValidateForm;
30+
dataForm.ValidateProperty += this.OnDataFormValidateProperty;
31+
}
32+
33+
this.saveButton = bindable.FindByName<Button>("saveButton");
34+
if (this.saveButton != null)
35+
{
36+
this.saveButton.Clicked += OnSaveButtonClicked;
37+
}
38+
}
39+
40+
/// <summary>
41+
/// Invokes on data form item validation.
42+
/// </summary>
43+
/// <param name="sender">The data form.</param>
44+
/// <param name="e">The event arguments.</param>
45+
private void OnDataFormValidateProperty(object? sender, DataFormValidatePropertyEventArgs e)
46+
{
47+
if (e.PropertyName == nameof(ContactFormModel.Mobile) && !e.IsValid)
48+
{
49+
e.ErrorMessage = e.NewValue == null || string.IsNullOrEmpty(e.NewValue.ToString()) ? "Please enter the mobile number" : "Invalid mobile number";
50+
}
51+
}
52+
53+
/// <summary>
54+
/// Invokes on manual data form validation.
55+
/// </summary>
56+
/// <param name="sender">The data form.</param>
57+
/// <param name="e">The event arguments.</param>
58+
private async void OnDataFormValidateForm(object? sender, DataFormValidateFormEventArgs e)
59+
{
60+
if (this.dataForm != null && App.Current?.MainPage != null)
61+
{
62+
if (e.ErrorMessage != null && e.ErrorMessage.Count > 0)
63+
{
64+
if (e.ErrorMessage.Count == 2)
65+
{
66+
await App.Current.MainPage.DisplayAlert("", "Please enter the contact name and mobile number", "OK");
67+
}
68+
else
69+
{
70+
if (e.ErrorMessage.ContainsKey(nameof(ContactFormModel.Name)))
71+
{
72+
await App.Current.MainPage.DisplayAlert("", "Please enter the contact name", "OK");
73+
}
74+
else
75+
{
76+
await App.Current.MainPage.DisplayAlert("", "Please enter the mobile number", "OK");
77+
}
78+
}
79+
}
80+
else
81+
{
82+
await App.Current.MainPage.DisplayAlert("", "Contact saved", "OK");
83+
}
84+
}
85+
}
86+
87+
/// <summary>
88+
/// Invokes on save button click.
89+
/// </summary>
90+
/// <param name="sender">The button.</param>
91+
/// <param name="e">The event arguments.</param>
92+
private void OnSaveButtonClicked(object? sender, EventArgs e)
93+
{
94+
this.dataForm?.Validate();
95+
}
96+
97+
/// <inheritdoc/>
98+
protected override void OnDetachingFrom(ContentPage bindable)
99+
{
100+
base.OnDetachingFrom(bindable);
101+
if (this.dataForm != null)
102+
{
103+
this.dataForm.ValidateForm -= this.OnDataFormValidateForm;
104+
this.dataForm.ValidateProperty -= this.OnDataFormValidateProperty;
105+
this.dataForm = null;
106+
}
107+
108+
if (this.saveButton != null)
109+
{
110+
this.saveButton.Clicked -= OnSaveButtonClicked;
111+
this.saveButton = null;
112+
}
113+
}
114+
}
115+
}

DataFormMAUI/DataBase/Constants.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace DataFormMAUI
8+
{
9+
public static class Constants
10+
{
11+
public const string DatabaseFilename = "SQLiteDB.db";
12+
13+
public const SQLite.SQLiteOpenFlags Flags =
14+
// open the database in read/write mode
15+
SQLite.SQLiteOpenFlags.ReadWrite |
16+
// create the database if it doesn't exist
17+
SQLite.SQLiteOpenFlags.Create |
18+
// enable multi-threaded database access
19+
SQLite.SQLiteOpenFlags.SharedCache;
20+
21+
public static string DatabasePath =>
22+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), DatabaseFilename);
23+
}
24+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using SQLite;
2+
3+
namespace DataFormMAUI
4+
{
5+
public class SQLiteDatabase
6+
{
7+
readonly SQLiteAsyncConnection _database;
8+
9+
public SQLiteDatabase()
10+
{
11+
_database = new SQLiteAsyncConnection(Constants.DatabasePath, Constants.Flags);
12+
_database.CreateTableAsync<ContactFormModel>();
13+
}
14+
15+
public async Task<List<ContactFormModel>> GetContactsAsync()
16+
{
17+
return await _database.Table<ContactFormModel>().ToListAsync();
18+
}
19+
20+
public async Task<ContactFormModel> GetContactAsync(ContactFormModel item)
21+
{
22+
return await _database.Table<ContactFormModel>().Where(i => i.ID == item.ID).FirstOrDefaultAsync();
23+
}
24+
25+
public async Task<int> AddContactAsync(ContactFormModel item)
26+
{
27+
return await _database.InsertAsync(item);
28+
}
29+
30+
public Task<int> DeleteContactAsync(ContactFormModel item)
31+
{
32+
return _database.DeleteAsync(item);
33+
}
34+
35+
public Task<int> UpdateContactAsync(ContactFormModel item)
36+
{
37+
if (item.ID != 0)
38+
return _database.UpdateAsync(item);
39+
else
40+
return _database.InsertAsync(item);
41+
}
42+
}
43+
}

DataFormMAUI/DataFormMAUI.csproj

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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);net6.0-tizen</TargetFrameworks> -->
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>DataFormMAUI</RootNamespace>
10+
<UseMaui>true</UseMaui>
11+
<SingleProject>true</SingleProject>
12+
<ImplicitUsings>enable</ImplicitUsings>
13+
14+
<!-- Display name -->
15+
<ApplicationTitle>DataFormMAUI</ApplicationTitle>
16+
17+
<!-- App Identifier -->
18+
<ApplicationId>com.companyname.DataFormMAUI</ApplicationId>
19+
<ApplicationIdGuid>2beba2f6-f865-4786-ab24-e272690fa61d</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+
<None Remove="Resources\Fonts\InputLayoutIcons.ttf" />
53+
<None Remove="Resources\Images\Add.png" />
54+
<None Remove="Resources\Images\people_circle0.png" />
55+
<None Remove="Resources\Images\people_circle1.png" />
56+
<None Remove="Resources\Images\people_circle10.png" />
57+
<None Remove="Resources\Images\people_circle11.png" />
58+
<None Remove="Resources\Images\people_circle12.png" />
59+
<None Remove="Resources\Images\people_circle13.png" />
60+
<None Remove="Resources\Images\people_circle14.png" />
61+
<None Remove="Resources\Images\people_circle15.png" />
62+
<None Remove="Resources\Images\people_circle16.png" />
63+
<None Remove="Resources\Images\people_circle17.png" />
64+
<None Remove="Resources\Images\people_circle18.png" />
65+
<None Remove="Resources\Images\people_circle19.png" />
66+
<None Remove="Resources\Images\people_circle2.png" />
67+
<None Remove="Resources\Images\people_circle20.png" />
68+
<None Remove="Resources\Images\people_circle21.png" />
69+
<None Remove="Resources\Images\people_circle22.png" />
70+
<None Remove="Resources\Images\people_circle23.png" />
71+
<None Remove="Resources\Images\people_circle24.png" />
72+
<None Remove="Resources\Images\people_circle25.png" />
73+
<None Remove="Resources\Images\people_circle26.png" />
74+
<None Remove="Resources\Images\people_circle27.png" />
75+
<None Remove="Resources\Images\people_circle3.png" />
76+
<None Remove="Resources\Images\people_circle4.png" />
77+
<None Remove="Resources\Images\people_circle5.png" />
78+
<None Remove="Resources\Images\people_circle6.png" />
79+
<None Remove="Resources\Images\people_circle7.png" />
80+
<None Remove="Resources\Images\people_circle8.png" />
81+
<None Remove="Resources\Images\people_circle9.png" />
82+
</ItemGroup>
83+
84+
<ItemGroup>
85+
<PackageReference Include="sqlite-net-pcl" Version="1.9.141-beta" />
86+
<PackageReference Include="Syncfusion.Maui.DataForm" Version="23.2.7" />
87+
<PackageReference Include="Syncfusion.Maui.ListView" Version="23.2.7" />
88+
</ItemGroup>
89+
90+
<ItemGroup>
91+
<MauiXaml Update="Views\EditPage.xaml">
92+
<Generator>MSBuild:Compile</Generator>
93+
</MauiXaml>
94+
</ItemGroup>
95+
96+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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>net8.0-windows10.0.19041.0</ActiveDebugFramework>
6+
<ActiveDebugProfile>Windows Machine</ActiveDebugProfile>
7+
</PropertyGroup>
8+
</Project>

DataFormMAUI/DataFormMAUI.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}") = "DataFormMAUI", "DataFormMAUI.csproj", "{AE859F5B-EE95-4D92-8F5E-079DA46CAEFE}"
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+
{AE859F5B-EE95-4D92-8F5E-079DA46CAEFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{AE859F5B-EE95-4D92-8F5E-079DA46CAEFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{AE859F5B-EE95-4D92-8F5E-079DA46CAEFE}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{AE859F5B-EE95-4D92-8F5E-079DA46CAEFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{AE859F5B-EE95-4D92-8F5E-079DA46CAEFE}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{AE859F5B-EE95-4D92-8F5E-079DA46CAEFE}.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

DataFormMAUI/MauiProgram.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Syncfusion.Maui.Core.Hosting;
2+
3+
namespace DataFormMAUI;
4+
5+
public static class MauiProgram
6+
{
7+
public static MauiApp CreateMauiApp()
8+
{
9+
var builder = MauiApp.CreateBuilder();
10+
builder
11+
.UseMauiApp<App>()
12+
.ConfigureFonts(fonts =>
13+
{
14+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
15+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
16+
//// Register custom font label
17+
fonts.AddFont("InputLayoutIcons.ttf", "InputLayoutIcons");
18+
});
19+
builder.ConfigureSyncfusionCore();
20+
return builder.Build();
21+
}
22+
}

0 commit comments

Comments
 (0)