private Task <ObservableDiagram> RenderChordAsync(IChordFinderResult result) { return(Task <ObservableDiagram> .Factory.StartNew(() => { ObservableDiagram od = null; AppVM.AppView.DoOnUIThread(() => { try { od = new ObservableDiagram(result.ToDiagram(Style), name: Strings.FinderResultDiagramName); od.PostEditCallback = (changed) => { if (changed) { od.Refresh(); } }; } catch (Exception ex) { ExceptionUtils.HandleException(ex); } }); return od; })); }
private Action <bool> GetDiagramPostEditCallback(ObservableDiagram od) { ObservableDiagram originalObservableDiagram = od; Diagram originalDiagram = od.Diagram; return((changed) => { if (changed) { if (Collection.Contains(originalDiagram)) { // We edited an existing diagram, so we need to replace the pre-edited Diagram still in the library // with the newly minted Diagram from the editor Collection.Replace(originalDiagram, originalObservableDiagram.Diagram); } else { // This was a new diagram, so we need to add it to the library collection Collection.Add(originalObservableDiagram.Diagram); // Then add it to the list of visible diagrams Diagrams.Add(originalObservableDiagram); } // Now we need to refresh the individual image originalObservableDiagram.Refresh(); // Now that the internal Diagram has changed, we need to rebuild the callback so that the new Diagram is // cached correctly for any future calls to edit this od originalObservableDiagram.PostEditCallback = GetDiagramPostEditCallback(originalObservableDiagram); } }); }