Title Back Colour Keyoti Title Line Title Curve
Blue Box Top

want to show custom context menu on correct word - RapidSpell WPF - Forum

Welcome Guest Search | Active Topics | Log In | Register

Options
ManojPatel
#1 Posted : Tuesday, October 21, 2014 8:13:20 PM
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
ManojPatel
#2 Posted : Thursday, October 23, 2014 2:19:35 PM
Rank: Member

Groups: Registered

Joined: 10/21/2014
Posts: 7
Can anybody reply to my question?
Jim
#3 Posted : Thursday, October 23, 2014 5:40:55 PM
Rank: Advanced Member

Groups: Administrators, Registered

Joined: 8/13/2004
Posts: 2,667
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!


Jim
#4 Posted : Friday, October 24, 2014 1:24:04 AM
Rank: Advanced Member

Groups: Administrators, Registered

Joined: 8/13/2004
Posts: 2,667
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!


ManojPatel
#5 Posted : Monday, October 27, 2014 3:25:31 PM
Rank: Member

Groups: Registered

Joined: 10/21/2014
Posts: 7
Thanks Jim.
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.




About | Contact | Site Map | Privacy Policy

Copyright © 2002- Keyoti Inc.