Skip to content

Instantly share code, notes, and snippets.

@cwensley
Last active November 30, 2016 18:30
Show Gist options
  • Save cwensley/00e2bb2e489bfb9717c47d886c17a5b0 to your computer and use it in GitHub Desktop.
Save cwensley/00e2bb2e489bfb9717c47d886c17a5b0 to your computer and use it in GitHub Desktop.
Shows how to add a Spell Check item to the RichText context menu on WPF using a native style in Eto.Forms.
using System;
using swc = System.Windows.Controls;
using swi = System.Windows.Input;
using Eto;
using Eto.Forms;
using Eto.Drawing;
namespace TestWpfSpellCheckMenuItem
{
class Startup
{
[STAThread]
static void Main(string[] args)
{
bool enableSpellCheck = true;
Style.Add<Eto.Wpf.Forms.Controls.RichTextAreaHandler>(null, h =>
{
h.SpellCheck = enableSpellCheck;
var menu = new swc.ContextMenu();
menu.Items.Add(new swc.MenuItem { Command = swi.ApplicationCommands.Cut });
menu.Items.Add(new swc.MenuItem { Command = swi.ApplicationCommands.Copy });
menu.Items.Add(new swc.MenuItem { Command = swi.ApplicationCommands.Paste });
menu.Items.Add(new swc.Separator());
var toggleSpellCheck = new swc.MenuItem
{
Header = "Spell Check",
IsCheckable = true,
IsChecked = h.SpellCheck,
};
toggleSpellCheck.Checked += (sender, e) => h.SpellCheck = enableSpellCheck = true;
toggleSpellCheck.Unchecked += (sender, e) => h.SpellCheck = enableSpellCheck = false;
menu.Items.Add(toggleSpellCheck);
h.Control.ContextMenu = menu;
});
new Application(new Eto.Wpf.Platform()).Run(new Form
{
Content = new TableLayout
{
Padding = 10,
Spacing = new Size(5, 5),
Rows =
{
"RichTextArea with spell check context menu:",
new RichTextArea()
}
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment