Skip to content

Commit 9248959

Browse files
Merge pull request #2 from SriRadheshNagS/UpdatedSample
950873-Updated .NET Version for Dataform sample
2 parents 25a3462 + e34a2d6 commit 9248959

File tree

8 files changed

+47
-28
lines changed

8 files changed

+47
-28
lines changed
Binary file not shown.
Binary file not shown.

LoginForm/LoginForm/App.xaml.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ public partial class App : Application
55
public App()
66
{
77
InitializeComponent();
8-
9-
MainPage = new MainPage();
108
}
9+
10+
protected override Window CreateWindow(IActivationState? activationState)
11+
{
12+
return new Window(new MainPage());
13+
}
1114
}

LoginForm/LoginForm/Behavior/LoginFormBehavior.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public class LoginFormBehavior : Behavior<ContentPage>
1515
/// <summary>
1616
/// Holds the data form object.
1717
/// </summary>
18-
private SfDataForm dataForm;
18+
private SfDataForm? dataForm;
1919

2020
/// <summary>
2121
/// Holds the login button instance.
2222
/// </summary>
23-
private Button loginButton;
23+
private Button? loginButton;
2424

2525
protected override void OnAttachedTo(ContentPage bindable)
2626
{
@@ -41,7 +41,7 @@ protected override void OnAttachedTo(ContentPage bindable)
4141
/// </summary>
4242
/// <param name="sender">The data form.</param>
4343
/// <param name="e">The event arguments.</param>
44-
private void OnGenerateDataFormItem(object sender, GenerateDataFormItemEventArgs e)
44+
private void OnGenerateDataFormItem(object? sender, GenerateDataFormItemEventArgs e)
4545
{
4646
if (e.DataFormItem != null && e.DataFormItem.FieldName == nameof(LoginFormModel.Email) && e.DataFormItem is DataFormTextEditorItem textItem)
4747
{
@@ -54,17 +54,17 @@ private void OnGenerateDataFormItem(object sender, GenerateDataFormItemEventArgs
5454
/// </summary>
5555
/// <param name="sender">The login button.</param>
5656
/// <param name="e">The event arguments.</param>
57-
private async void OnLoginButtonCliked(object sender, EventArgs e)
57+
private async void OnLoginButtonCliked(object? sender, EventArgs e)
5858
{
59-
if (this.dataForm != null && App.Current?.MainPage != null)
59+
if (this.dataForm != null)
6060
{
6161
if (this.dataForm.Validate())
6262
{
63-
await App.Current.MainPage.DisplayAlert("", "Signed in successfully", "OK");
63+
await DisplayAlert("", "Signed in successfully", "OK");
6464
}
6565
else
6666
{
67-
await App.Current.MainPage.DisplayAlert("", "Please enter the required details", "OK");
67+
await DisplayAlert("", "Please enter the required details", "OK");
6868
}
6969
}
7070
}
@@ -82,5 +82,18 @@ protected override void OnDetachingFrom(ContentPage bindable)
8282
this.dataForm.GenerateDataFormItem -= this.OnGenerateDataFormItem;
8383
}
8484
}
85+
86+
/// <summary>
87+
/// Displays an alert dialog to the user.
88+
/// </summary>
89+
/// <param name="title">The title of the alert dialog.</param>
90+
/// <param name="message">The message to display.</param>
91+
/// <param name="cancel">The text for the cancel button.</param>
92+
/// <returns>A task representing the asynchronous alert display operation.</returns>
93+
private Task DisplayAlert(string title, string message, string cancel)
94+
{
95+
return App.Current?.Windows?[0]?.Page!.DisplayAlert(title, message, cancel)
96+
?? Task.FromResult(false);
97+
}
8598
}
8699
}

LoginForm/LoginForm/LoginForm.csproj

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<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>
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>
66
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
77
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
88
<OutputType>Exe</OutputType>
99
<RootNamespace>LoginForm</RootNamespace>
1010
<UseMaui>true</UseMaui>
1111
<SingleProject>true</SingleProject>
1212
<ImplicitUsings>enable</ImplicitUsings>
13+
<Nullable>enable</Nullable>
1314

1415
<!-- Display name -->
1516
<ApplicationTitle>LoginForm</ApplicationTitle>
@@ -55,7 +56,20 @@
5556

5657

5758
<ItemGroup>
58-
<PackageReference Include="Syncfusion.Maui.DataForm" Version="24.1.41" />
59+
<PackageReference Include="Syncfusion.Maui.DataForm" Version="*" />
60+
</ItemGroup>
61+
62+
63+
64+
<ItemGroup>
65+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
66+
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
67+
</ItemGroup>
68+
69+
70+
71+
<ItemGroup>
72+
<PackageReference Update="Microsoft.Maui.Controls.Compatibility" Version="9.0.60" />
5973
</ItemGroup>
6074

6175

LoginForm/LoginForm/LoginForm.csproj.user

Lines changed: 0 additions & 12 deletions
This file was deleted.

LoginForm/LoginForm/MainPage.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
xmlns:dataForm="clr-namespace:Syncfusion.Maui.DataForm;assembly=Syncfusion.Maui.DataForm"
66
xmlns:local="clr-namespace:LoginForm"
77
xmlns:system="clr-namespace:System;assembly=netstandard"
8+
x:DataType="local:DataFormViewModel"
89
x:Class="LoginForm.MainPage">
910
<ContentPage.BindingContext>
1011
<local:DataFormViewModel/>
@@ -19,7 +20,7 @@
1920
<Image Source="login.png" Grid.Row="0" Grid.Column="0" HorizontalOptions="Center" Aspect="AspectFit"/>
2021
</Border>
2122

22-
<Frame CornerRadius="10" Grid.Column="{OnPlatform Default=0, WinUI=1, MacCatalyst=1}" BorderColor="White" HeightRequest="420" Background="White"
23+
<Border Grid.Column="{OnPlatform Default=0, WinUI=1, MacCatalyst=1}" HeightRequest="420" Background="White"
2324
Grid.Row="{OnPlatform Default=1, WinUI=0,MacCatalyst=0}"
2425
WidthRequest="380" VerticalOptions="{OnPlatform Default=Start, WinUI=Center , MacCatalyst=Center}"
2526
Grid.ColumnSpan="{OnPlatform Default=2, WinUI=1, MacCatalyst=1}"
@@ -77,7 +78,7 @@
7778
</Label.FormattedText>
7879
</Label>
7980
</Grid>
80-
</Frame>
81+
</Border>
8182
</Grid>
8283
<ContentPage.Behaviors>
8384
<local:LoginFormBehavior/>

LoginForm/LoginForm/Model/LoginFormModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public class LoginFormModel
1212
{
1313
[Display(Prompt = "example@mail.com", Name = "Email")]
1414
[EmailAddress(ErrorMessage = "Enter your email - example@mail.com")]
15-
public string Email { get; set; }
15+
public string Email { get; set; } = string.Empty;
1616

1717
[Display(Name = "Password")]
1818
[DataType(DataType.Password)]
1919
[Required(ErrorMessage = "Enter the password")]
20-
public string Password { get; set; }
20+
public string Password { get; set; } = string.Empty;
2121
}
2222
}

0 commit comments

Comments
 (0)