Skip to content

Commit 788e3d2

Browse files
Committed property changes issue
1 parent e163851 commit 788e3d2

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

DataFormMAUI/Behavior/ContactFormBehavior.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class ContactFormBehavior : Behavior<ContentPage>
1313
/// </summary>
1414
private SfDataForm? dataForm;
1515

16+
private bool isValid;
17+
1618
/// <summary>
1719
/// Holds the save button instance.
1820
/// </summary>
@@ -36,7 +38,7 @@ protected override void OnAttachedTo(ContentPage bindable)
3638
this.saveButton.Clicked += OnSaveButtonClicked;
3739
}
3840
}
39-
41+
4042
/// <summary>
4143
/// Invokes on data form item validation.
4244
/// </summary>
@@ -76,13 +78,13 @@ private async void OnDataFormValidateForm(object? sender, DataFormValidateFormEv
7678
await App.Current.MainPage.DisplayAlert("", "Please enter the mobile number", "OK");
7779
}
7880
}
81+
isValid = false;
82+
7983
}
8084
else
8185
{
82-
App.Database.UpdateContactAsync((this.dataForm.BindingContext as ContactsViewModel).SelectedItem);
83-
84-
await App.Current.MainPage.Navigation.PopAsync();
85-
await App.Current.MainPage.DisplayAlert("", "Contact saved", "OK");
86+
isValid = true;
87+
8688
}
8789
}
8890
}
@@ -92,9 +94,15 @@ private async void OnDataFormValidateForm(object? sender, DataFormValidateFormEv
9294
/// </summary>
9395
/// <param name="sender">The button.</param>
9496
/// <param name="e">The event arguments.</param>
95-
private void OnSaveButtonClicked(object? sender, EventArgs e)
97+
private async void OnSaveButtonClicked(object? sender, EventArgs e)
9698
{
9799
this.dataForm?.Validate();
100+
101+
if(isValid)
102+
{
103+
await App.Current.MainPage.DisplayAlert("", "Contact saved", "OK");
104+
await App.Current.MainPage.Navigation.PopAsync();
105+
}
98106
}
99107

100108
/// <inheritdoc/>

DataFormMAUI/Model/ContactFormModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public string Mobile
3939
{
4040
mobile = new string(value.Where(c => Char.IsLetterOrDigit(c)).ToArray());
4141
}
42-
RaisePropertyChanged(nameof(Mobile));
4342
if (mobile.Length == 10)
4443
this.MaskedMobileText = string.Format("({0}) {1}-{2}", mobile.Substring(0, 3), mobile.Substring(3, 3), mobile.Substring(6));
44+
RaisePropertyChanged(nameof(Mobile));
4545
}
4646
}
4747
}
@@ -71,7 +71,6 @@ public string MaskedMobileText
7171
set
7272
{
7373
this.maskedMobileText = value;
74-
RaisePropertyChanged(nameof(MaskedMobileText));
7574
}
7675
}
7776

DataFormMAUI/Views/EditPage.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,16 @@ public EditPage()
66
{
77
InitializeComponent();
88
}
9+
10+
protected override void OnAppearing()
11+
{
12+
base.OnAppearing();
13+
(this.contactForm.DataObject as ContactFormModel).PropertyChanged += ContactFormBehavior_PropertyChanged;
14+
}
15+
16+
private void ContactFormBehavior_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
17+
{
18+
App.Database.UpdateContactAsync(this.contactForm.DataObject as ContactFormModel);
19+
}
920
}
1021
}

0 commit comments

Comments
 (0)