|
Rank: Member
Groups: Registered
Joined: 10/21/2014 Posts: 7
|
Hi,
I am using RapidSpellAsYouType control (Keyoti4.RapidSpell.WPF.dll ver 3.0.12.826) in my WPF application. I want to display my custom static context menu when user right clicks on correct word. Otherwise the suggestion list should be display when user right clicks on incorrect word. Please let me know on how to achieve this functionality.
Here is the sample code for your reference: File: MainWindow.xaml
<Window x:Class="WPFSpellchekerDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:Keyoti.RapidSpell.Wpf;assembly=Keyoti4.RapidSpell.WPF"> <Grid> <TextBox Height="135" HorizontalAlignment="Left" Margin="54,82,0,0" Name="textBox1" VerticalAlignment="Top" Width="387" TextWrapping="Wrap"> <TextBox.Text>In this example we have set the ShowSuggestionsContextMenu property to false to allow us to override the built-in menu. We have added a ContextMenu as usual to the TextBox. On the ContextMenu.Opened event we grab suggestions from the spell checker if there are any and build the menu. </TextBox.Text> <TextBox.ContextMenu> <ContextMenu Name="textBoxContextMenu" > <MenuItem Command="ApplicationCommands.Undo" Header="Undo" IsEnabled="True"/> <Separator /> <MenuItem Command="ApplicationCommands.Cut" Header="Cut" IsEnabled="True"/> <MenuItem Command="ApplicationCommands.Copy" Header="Copy" /> <MenuItem Command="ApplicationCommands.Paste" Header="Paste" IsEnabled="True"/> <MenuItem Command="EditingCommands.Delete" Header="Delete" InputGestureText="Del" IsEnabled="True"/> <Separator /> <MenuItem Command="ApplicationCommands.SelectAll" Header="Select All" /> </ContextMenu> </TextBox.ContextMenu> </TextBox> <my:RapidSpellAsYouType Height="28" HorizontalAlignment="Left" Margin="-259,138,0,0" Name="rapidSpellAsYouType1" VerticalAlignment="Top" Width="86" /> </Grid> </Window>
File: MainWindow.xaml.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;
namespace WPFSpellchekerDemo { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); rapidSpellAsYouType1.AddTextComponent(textBox1); } } }
Thanks, Manoj Patel
|
|
Rank: Member
Groups: Registered
Joined: 10/21/2014 Posts: 7
|
Can anybody reply to my question?
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Yes, I am sorry - I usually have the page open on active posts, but somehow I missed your post. Will answer shortly. Jim -your feedback is helpful to other users, thank you!-your feedback is helpful to other users, thank you!
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Unfortunately because you cannot Clone a WPF MenuItem, we can't automatically use your context menu for off spell clicks. To do what you want you need to use the ContextMenu.Opened event eg. Code: public MainWindow() { InitializeComponent(); rapidSpellAsYouType1.AddTextComponent(textBox1); textBoxContextMenu.Opened += new RoutedEventHandler(textBoxContextMenu_Opened); }
void textBoxContextMenu_Opened(object sender, RoutedEventArgs e) { textBoxContextMenu.Items.Clear(); object[] spellItems = rapidSpellAsYouType1.GetSuggestions(); if (spellItems != null) { foreach (object s in spellItems) textBoxContextMenu.Items.Add(s); } else {
textBoxContextMenu.Items.Add(new MenuItem(){ Header = "Undo", IsEnabled = true, Command = ApplicationCommands.Undo });
textBoxContextMenu.Items.Add(new Separator());
textBoxContextMenu.Items.Add(new MenuItem(){ Header = "Cut", IsEnabled = true, Command = ApplicationCommands.Cut });
textBoxContextMenu.Items.Add(new MenuItem(){ Header = "Copy", IsEnabled = true, Command = ApplicationCommands.Copy });
textBoxContextMenu.Items.Add(new MenuItem(){ Header = "Paste", IsEnabled = true, Command = ApplicationCommands.Paste });
textBoxContextMenu.Items.Add(new MenuItem(){ Header = "Delete", IsEnabled = true, Command = ApplicationCommands.Undo, InputGestureText="Del" });
textBoxContextMenu.Items.Add(new Separator());
textBoxContextMenu.Items.Add(new MenuItem(){ Header = "Select All", IsEnabled = true, Command = ApplicationCommands.SelectAll });
}
I don't think it can be done in XAML, sorry. Best Jim -your feedback is helpful to other users, thank you!-your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 10/21/2014 Posts: 7
|
|
|