Skip to content

Commit edbd480

Browse files
Sample updated
1 parent 92d2ac4 commit edbd480

22 files changed

+187
-166
lines changed

DataFormMAUI/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public App()
66
{
77
InitializeComponent();
88

9-
MainPage = new NavigationPage(new MainPage());
9+
MainPage = new NavigationPage(new MainPage());
1010

1111
}
1212

@@ -27,7 +27,7 @@ public static SQLiteDatabase Database
2727
protected override Window CreateWindow(IActivationState activationState)
2828
{
2929
var window = base.CreateWindow(activationState);
30-
window.Width = 400;
30+
window.Width = 450;
3131
return window;
3232
}
3333
}

DataFormMAUI/Behavior/ContactFormBehavior.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected override void OnAttachedTo(ContentPage bindable)
4444
/// <param name="e">The event arguments.</param>
4545
private void OnDataFormValidateProperty(object? sender, DataFormValidatePropertyEventArgs e)
4646
{
47-
if (e.PropertyName == nameof(ContactFormModel.Mobile) && !e.IsValid)
47+
if (e.PropertyName == nameof(ContactFormModel.Mobile) && !e.IsValid)
4848
{
4949
e.ErrorMessage = e.NewValue == null || string.IsNullOrEmpty(e.NewValue.ToString()) ? "Please enter the mobile number" : "Invalid mobile number";
5050
}
@@ -79,6 +79,9 @@ private async void OnDataFormValidateForm(object? sender, DataFormValidateFormEv
7979
}
8080
else
8181
{
82+
App.Database.UpdateContactAsync((this.dataForm.BindingContext as ContactsViewModel).SelectedItem);
83+
84+
await App.Current.MainPage.Navigation.PopAsync();
8285
await App.Current.MainPage.DisplayAlert("", "Contact saved", "OK");
8386
}
8487
}

DataFormMAUI/DataBase/DatabaseConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public static class DatabaseConstants
44
{
5-
public const string DatabaseFilename = "SQLiteDB.db";
5+
public const string DatabaseFilename = "DataFormSQLiteDB.db";
66

77
public const SQLite.SQLiteOpenFlags Flags =
88
// open the database in read/write mode

DataFormMAUI/DataBase/SQLiteDatabase.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,40 @@ namespace DataFormMAUI
44
{
55
public class SQLiteDatabase
66
{
7-
readonly SQLiteAsyncConnection _database;
7+
readonly SQLiteConnection _database;
88

99
public SQLiteDatabase()
1010
{
11-
_database = new SQLiteAsyncConnection(DatabaseConstants.DatabasePath, DatabaseConstants.Flags);
12-
_database.CreateTableAsync<ContactFormModel>();
11+
_database = new SQLiteConnection(DatabaseConstants.DatabasePath, DatabaseConstants.Flags);
12+
_database.CreateTable<ContactFormModel>();
1313
}
1414

15-
public async Task<List<ContactFormModel>> GetContactsAsync()
15+
public List<ContactFormModel> GetContactsAsync()
1616
{
17-
return await _database.Table<ContactFormModel>().ToListAsync();
17+
return _database.Table<ContactFormModel>().ToList();
1818
}
1919

20-
public async Task<ContactFormModel> GetContactAsync(ContactFormModel item)
20+
public ContactFormModel GetContactAsync(ContactFormModel item)
2121
{
22-
return await _database.Table<ContactFormModel>().Where(i => i.ID == item.ID).FirstOrDefaultAsync();
22+
return _database.Table<ContactFormModel>().Where(i => i.ID == item.ID).FirstOrDefault();
2323
}
2424

25-
public async Task<int> AddContactAsync(ContactFormModel item)
25+
public int AddContactAsync(ContactFormModel item)
2626
{
27-
return await _database.InsertAsync(item);
27+
return _database.Insert(item);
2828
}
2929

30-
public Task<int> DeleteContactAsync(ContactFormModel item)
30+
public int DeleteContactAsync(ContactFormModel item)
3131
{
32-
return _database.DeleteAsync(item);
32+
return _database.Delete(item);
3333
}
3434

35-
public Task<int> UpdateContactAsync(ContactFormModel item)
35+
public int UpdateContactAsync(ContactFormModel item)
3636
{
3737
if (item.ID != 0)
38-
return _database.UpdateAsync(item);
38+
return _database.Update(item);
3939
else
40-
return _database.InsertAsync(item);
40+
return _database.Insert(item);
4141
}
4242
}
4343
}

DataFormMAUI/DataFormMAUI.csproj

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
55
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
66
<!-- 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> -->
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+
816
<OutputType>Exe</OutputType>
917
<RootNamespace>DataFormMAUI</RootNamespace>
1018
<UseMaui>true</UseMaui>
@@ -15,15 +23,14 @@
1523
<ApplicationTitle>DataFormMAUI</ApplicationTitle>
1624

1725
<!-- App Identifier -->
18-
<ApplicationId>com.companyname.DataFormMAUI</ApplicationId>
19-
<ApplicationIdGuid>2beba2f6-f865-4786-ab24-e272690fa61d</ApplicationIdGuid>
26+
<ApplicationId>com.companyname.dataformmaui</ApplicationId>
2027

2128
<!-- Versions -->
2229
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
2330
<ApplicationVersion>1</ApplicationVersion>
2431

25-
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
26-
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
32+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
33+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
2734
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
2835
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
2936
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
@@ -39,7 +46,6 @@
3946

4047
<!-- Images -->
4148
<MauiImage Include="Resources\Images\*" />
42-
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
4349

4450
<!-- Custom Fonts -->
4551
<MauiFont Include="Resources\Fonts\*" />
@@ -49,48 +55,11 @@
4955
</ItemGroup>
5056

5157
<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>
58+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
59+
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
60+
<PackageReference Include="sqlite-net-pcl" Version="1.9.141-beta" />
61+
<PackageReference Include="Syncfusion.Maui.DataForm" Version="24.1.41" />
62+
<PackageReference Include="Syncfusion.Maui.ListView" Version="24.1.41" />
9463
</ItemGroup>
9564

9665
</Project>

DataFormMAUI/DataFormMAUI.csproj.user

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,27 @@
44
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
55
<ActiveDebugFramework>net8.0-windows10.0.19041.0</ActiveDebugFramework>
66
<ActiveDebugProfile>Windows Machine</ActiveDebugProfile>
7+
<SelectedPlatformGroup>Emulator</SelectedPlatformGroup>
8+
<DefaultDevice>tablet_m-dpi_10_1in_-_api_34</DefaultDevice>
79
</PropertyGroup>
10+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'">
11+
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
12+
</PropertyGroup>
13+
<ItemGroup>
14+
<None Update="App.xaml">
15+
<SubType>Designer</SubType>
16+
</None>
17+
<None Update="Platforms\Windows\App.xaml">
18+
<SubType>Designer</SubType>
19+
</None>
20+
<None Update="Platforms\Windows\Package.appxmanifest">
21+
<SubType>Designer</SubType>
22+
</None>
23+
<None Update="Resources\Styles\Colors.xaml">
24+
<SubType>Designer</SubType>
25+
</None>
26+
<None Update="Resources\Styles\Styles.xaml">
27+
<SubType>Designer</SubType>
28+
</None>
29+
</ItemGroup>
830
</Project>

DataFormMAUI/Model/ContactFormModel.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,29 @@ public class ContactFormModel
2020
[Display(ShortName = "Last name")]
2121
public string LastName { get; set; }
2222

23+
private string mobile;
24+
2325
[DataType(DataType.PhoneNumber)]
2426
[Required]
2527
[RegularExpression(@"^\(\d{3}\) \d{3}-\d{4}$", ErrorMessage = "Invalid phone number")]
26-
public string Mobile { get; set; }
28+
public string Mobile
29+
{
30+
get { return mobile; }
31+
set
32+
{
33+
mobile = value;
34+
if (!string.IsNullOrEmpty(mobile))
35+
{
36+
char[] specialCharacters = { '(', ')', '-', ' ' };
37+
if (mobile[0] == specialCharacters[0])
38+
{
39+
mobile = new string(value.Where(c => Char.IsLetterOrDigit(c)).ToArray());
40+
}
41+
if (mobile.Length == 10)
42+
this.MaskedMobileText = string.Format("({0}) {1}-{2}", mobile.Substring(0, 3), mobile.Substring(3, 3), mobile.Substring(6));
43+
}
44+
}
45+
}
2746

2847
[DataType(DataType.PhoneNumber)]
2948
public string Landline { get; set; }
@@ -41,5 +60,7 @@ public class ContactFormModel
4160

4261
public string Email { get; set; }
4362

63+
[Display(AutoGenerateField = false)]
64+
public string MaskedMobileText { get; set; }
4465
}
4566
}

DataFormMAUI/Model/ContactsInfoRepository.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@ namespace DataFormMAUI
44
{
55
class ContactsInfoRepository
66
{
7-
87
private Random random = new Random();
9-
public ContactFormModel ContactFormModel { get; set; }
10-
11-
public ContactsInfoRepository()
12-
{
13-
this.ContactFormModel = new ContactFormModel();
14-
}
158

169
public ObservableCollection<ContactFormModel> GetContactDetails(int count)
1710
{
@@ -21,8 +14,8 @@ public ObservableCollection<ContactFormModel> GetContactDetails(int count)
2114
{
2215
var details = new ContactFormModel()
2316
{
24-
ID = i+1,
25-
Mobile = random.Next(100, 400).ToString() + random.Next(500, 800).ToString() + random.Next(1000, 2000).ToString(),
17+
ID = i + 1,
18+
Mobile = random.Next(100, 400).ToString() + random.Next(500, 800).ToString() + random.Next(1000, 2000).ToString(),
2619
ProfileImage = "People_Circle" + (i % 19) + ".png",
2720
};
2821

@@ -176,7 +169,7 @@ public ObservableCollection<ContactFormModel> GetContactDetails(int count)
176169
"Xaviour",
177170
"Ryan ",
178171
"Connor ",
179-
"Michael",
172+
"Michael",
180173
};
181174
}
182175
}

DataFormMAUI/Platforms/Android/MainActivity.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
using Android.Content.PM;
33
using Android.OS;
44

5-
namespace DataFormMAUI;
6-
7-
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
8-
public class MainActivity : MauiAppCompatActivity
5+
namespace DataFormMAUI
96
{
7+
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
8+
public class MainActivity : MauiAppCompatActivity
9+
{
10+
}
1011
}
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
using Android.App;
22
using Android.Runtime;
33

4-
namespace DataFormMAUI;
5-
6-
[Application]
7-
public class MainApplication : MauiApplication
4+
namespace DataFormMAUI
85
{
9-
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
10-
: base(handle, ownership)
11-
{
12-
}
6+
[Application]
7+
public class MainApplication : MauiApplication
8+
{
9+
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
10+
: base(handle, ownership)
11+
{
12+
}
1313

14-
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
14+
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
15+
}
1516
}

0 commit comments

Comments
 (0)