public override async void OpenItemEditor(TItem item) { EditingItem = item; if (Form == null) { return; } Cache.Set(EdiTItemCacheKey, EditingItem.DeepClone(), ObjectCache.InfiniteAbsoluteExpiration); // cache item state so it can be restored later bool result = false; try { result = (bool)await DialogHost.Show(Form, (sender, args) => { OnItemEditorOpening(sender, new ItemEditorOpeningDialogEventArgs <TItem>(item)); }, (sender, args) => { ItemEditorClosingDialogEventArgs <TItem> extArgs = new ItemEditorClosingDialogEventArgs <TItem>(item); OnFormClosing(extArgs); if (extArgs.IsCancelled) { args.Cancel(); } }); } catch (Exception) { OnOpenFormFailed(item); return; } OnItemEdited(new ItemEditedEventArgs <TItem>(result, (TItem)Cache.Get(EdiTItemCacheKey), item)); Cache.Remove(EdiTItemCacheKey); }
private void DefaultOnFormClosing(object sender, ItemEditorClosingDialogEventArgs <TItem> e) { bool result = (bool)e.Result; bool canClose = CanCloseItemEditor(new ItemEditedEventArgs <TItem>(result, (TItem)Cache.Get(EdiTItemCacheKey), e.Item)); if (!canClose) { e.Cancel(); } }
public virtual async void OpenItemEditor(TItem item) { EditingItem = item; if (FormProvider == null) { return; } UsedForm = FormProvider.GetUIElement(); Cache.Set(EdiTItemCacheKey, EditingItem.DeepClone()); // cache item state so it can be restored later bool result = false; try { result = (bool)await DialogService.Show(UsedForm, (sender, args) => { OnItemEditorOpening(sender, new ItemEditorOpeningDialogEventArgs <TItem>(item)); if (args.ShouldClose) { args.Close(); } }, (sender, args) => { ItemEditorClosingDialogEventArgs <TItem> extArgs = new ItemEditorClosingDialogEventArgs <TItem>(args.Result, item); OnFormClosing(extArgs); if (extArgs.IsCancelled) { args.Cancel(); } }).ConfigureAwait(true); } catch (Exception ex) { Log.Error(ex, "Couldn't open form"); OnOpenFormFailed(item); return; } OnItemEdited(new ItemEditedEventArgs <TItem>(result, (TItem)Cache.Get(EdiTItemCacheKey), item)); Cache.Remove(EdiTItemCacheKey); }
protected virtual void OnFormClosing(ItemEditorClosingDialogEventArgs <TItem> e) => FormClosing.Invoke(this, e);