protected virtual bool CanCloseItemEditor(ItemEditedEventArgs <TItem> e)
 {
     if (e.Result)
     {
         ValidateResult result = ValidateResult.Valid;
         if (Validator != null)
         {
             result = Validator.Validate(e.ActualItem);
         }
         else if (e.ActualItem is IValidable validableItem)
         {
             result = validableItem.Validate();
         }
         if (!result.IsValid)
         {
             DialogService.ShowMessage($"Form is not valid, fix errors before saving:\n{result.Error}", "Invalid form");
             return(false);
         }
     }
     else
     {
         if (e.ActualItem.IsDirty)
         {
             return(DialogService.ShowMessage("Are you sure you want to exit form? Changes won't be saved", "Unsaved changes", "Yes", "No", null).Result);
         }
     }
     return(true);
 }
 private void DefaultOnItemEdited(object sender, ItemEditedEventArgs <TItem> args)
 {
     if (!args.Result)
     {
         args.ActualItem.CopyValues(args.CachedItem);
     }
 }
 protected virtual void OnItemEdited(ItemEditedEventArgs <TItem> e)
 {
     if (ItemEdited == null)
     {
         ItemEdited = DefaultOnItemEdited;
     }
     ItemEdited.Invoke(this, e);
 }
 protected override bool CanCloseItemEditor(ItemEditedEventArgs <TItem> e)
 {
     if (e.Result)
     {
         if (Validator != null)
         {
             ValidationResult validation = Validator.Validate(e.ActualItem);
             if (!validation.IsValid)
             {
                 DialogService.ShowMessage("Form is not valid, fix errors before saving", "Invalid form");
                 return(false);
             }
         }
     }
     else
     {
         if (e.ActualItem.IsDirty)
         {
             return(DialogService.ShowMessage("Are you sure you want to exit form? Changes won't be saved", "Unsaved changes", "Yes", "No", null).Result);
         }
     }
     return(true);
 }
Exemple #5
0
 protected virtual bool CanCloseItemEditor(ItemEditedEventArgs <TItem> e) => true;