// Drag and drop: Identifies the targeted glyph and calls backend to embed the SVG. private async void GridView_Drop(object sender, DragEventArgs e) { try { GlyphModel glyph = null; if (e.OriginalSource is StackPanel) { StackPanel target = e.OriginalSource as StackPanel; if (target.DataContext is GlyphModel) { glyph = target.DataContext as GlyphModel; foreach (SvgFileItem file in selectedSvgItems) { // Embed the selected SVG onto the selected glyph. await fontFile.AddSvgAsync(glyph.GlyphID, file.SVGFile); // Refresh the preview grid to reflect the modified font. await ReloadPreviewAsync(); } } } } catch (Exception exc) { await NotifyUserAsync("The app encountered an error while trying to add SVG to the font.", exc); return; } }
// When a glyph preview is right-clicked, instantiate a popup menu and allow the // user to delete that glyph's SVG glyph if present. public async void Glyph_RightTapped(object sender, RightTappedRoutedEventArgs e) { // Prepare the context menu. PopupMenu menu = new PopupMenu(); menu.Commands.Add(new UICommand("Delete SVG", async(command) => { // Retrieve the selected Characer object. GlyphModel glyph = null; if (e.OriginalSource is TextBlock) { TextBlock target = e.OriginalSource as TextBlock; if (target.DataContext is GlyphModel) { glyph = target.DataContext as GlyphModel; try { // Call the backend to remove the specified SVG. await fontFile.RemoveSvgAsync(glyph.GlyphID); // Refresh the preview grid to reflect the updated font. await ReloadPreviewAsync(); } catch (Exception exc) { await NotifyUserAsync("The app encountered an error while trying to remove SVG from the font.", exc); return; } } } })); // Invoke the context menu. await menu.ShowForSelectionAsync(GetElementRect((FrameworkElement)sender)); }