This is a migrated thread and some comments may be shown as answers.

RadContextMenu on Rightclick for Silverlight controls

13 Answers 143 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Abhi
Top achievements
Rank 1
Abhi asked on 08 Jan 2013, 09:26 AM
Hi,
      On Rightclick on silverlight textbox, I displayed RadContextMenu with cut, copy and paste functionalities, but the problem I am facing here is, the displaying contextmenu is not at the place where I am Rightclicking, instead it is displaying some where else.......
Please help........

13 Answers, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 08 Jan 2013, 10:21 PM
Hi Abhi,

You can set the Placement of RadContextMenu to MousePoint. You can try the code below:
<TextBox Text="This is TextBox with RadContextMenu" Background="AliceBlue" VerticalAlignment="Top">
    <telerik:RadContextMenu.ContextMenu>
        <telerik:RadContextMenu Placement="MousePoint">
            <telerik:RadMenuItem Header="Item 1"/>
            <telerik:RadMenuItem Header="Item 2"/>
            <telerik:RadMenuItem Header="Item 3">
                <telerik:RadMenuItem Header="Item 3.1"/>
                <telerik:RadMenuItem Header="Item 3.2"/>
                <telerik:RadMenuItem Header="Item 3.3"/>
            </telerik:RadMenuItem>
        </telerik:RadContextMenu>
    </telerik:RadContextMenu.ContextMenu>
</TextBox>

Hopefully this helps!

Kind regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Abhi
Top achievements
Rank 1
answered on 09 Jan 2013, 08:00 AM
Hi  Rosen Vladimirov,
                                   Thank you very much

But, I am adding the context menu through code behind for a textbox........

there I used....

contextmenu.PlacementTarget = textbox1;
contextmenu.IsOpen = true;

After using this, if rightclick(where-ever) inside the textbox then it is showing the contextmenu at left-bottom-corner of the textbox..........

Solution I got....

I removed

contextmenu.PlacementTarget = textbox1;
contextmenu.IsOpen = true;

and Instead, I used,

RadContextMenu.SetContextMenu(textbox1, contextmenu);


Now it is working fine...........Thanks again

 

0
Abhi
Top achievements
Rank 1
answered on 10 Jan 2013, 05:55 AM

AutoCompleteBox t = new AutoCompleteBox();
TextBox textbox = new TextBox();

t = this as AutoCompleteBox;

if (string.IsNullOrEmpty(textbox.SelectedText))

{

 

 _cut.IsEnabled = false;

_copy.IsEnabled = false;

}

 

 

I am Implementing RadcontextMenu for autocompletebox in base class for cut, copy paste functionalities....
In order to get the selected text inside the autocompletebox I just used

textbox = VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(t, 0), 0) as TextBox;

while debugging I observed that it returns the null value for the textbox, and I got the exception (object reference not set to an instance of an object) in the nextline..

textbox.SelectedText gives that exception

if (string.IsNullOrEmpty(textbox.SelectedText))

{

_cut.IsEnabled = false;
_copy.IsEnabled = false;
}

 
please give solution for this..........

 

 

 

 

 

 

0
Rosen Vladimirov
Telerik team
answered on 10 Jan 2013, 10:42 AM
Hi Abhi,

I would suggest you to check our RadAutoCompleteBox. You should use the SelectedItems collection of RadAutoCompleteBox. You shouldn't use a separate textBox. For example:
foreach (string item in radAutoCompleteBox.SelectedItems)
{
    MessageBox.Show("Selected item: " + item);
}

This should do the trick for you.

Regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Abhi
Top achievements
Rank 1
answered on 10 Jan 2013, 12:05 PM
Hi,
        can u just give one sample for
       
        RadContextmenu with autocompletebox to provide cut, copy, paste fuctionality on rightclick on it.
0
Rosen Vladimirov
Telerik team
answered on 10 Jan 2013, 03:13 PM
Hello Abhi,

First of all, please post your questions at only one place. We are monitoring our forums and there's no need to post the same question many times.
Now forward to your problem - I've created a simple project for you with one RadAutoCompleteBox and one AutoCompleteBox. Both have RadContextMenu attached.

Hopefully the attached project will help you to resolve your issues.

Greetings,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Abhi
Top achievements
Rank 1
answered on 15 Jan 2013, 09:16 AM
thank you very much
I got it..............
0
Abhi
Top achievements
Rank 1
answered on 15 Jan 2013, 10:53 AM
On Rightclick, RadcontextMenu is Opened but the selectedtext is no longer visible.........



0
Rosen Vladimirov
Telerik team
answered on 17 Jan 2013, 02:17 PM
Hello Abhi,

May I ask you for more details about your problem as from your description I'm not able to understand the exact issue. It will be great if you could send us a sample project illustrating this unexpected behavior.

Looking forward to hearing from you.

Kind regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Abhi
Top achievements
Rank 1
answered on 18 Jan 2013, 02:08 PM
Hi,
      If I select some part of the text inside editable combobox and rightclicking on it displays a radcontextmenu, but at this point all text are selected in the box, instead what I selected before rightclicking on it (I selected only a part of it)...........pls give any solution for this..

xaml code is
<UserControl x:Class="textboxExample.MainPage"
    mc:Ignorable="d"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"     
    xmlns:local="clr-namespace:textboxExample"    
    xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
    xmlns:telerikinputcontrols="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"           
    Height="300" Width="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
 
    <Grid x:Name="LayoutRoot" Background="White">
        <telerikinputcontrols:RadComboBox Name="c" IsEditable="True" Height="24" Width="171" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="84,41,0,0" />
    </Grid>
 
</UserControl>

xaml.cs code is
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Telerik.Windows.Controls;
using Telerik.Windows;
using Telerik.Windows.Controls.Navigation;
 
 
namespace textboxExample
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            c.MouseRightButtonDown += new MouseButtonEventHandler(c_MouseRightButtonDown);
 
        }
 
        void c_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            RadContextMenu r = new RadContextMenu();
            r = BuildMenu();
            r.Opened += new RoutedEventHandler(r_Opened);
            RadContextMenu.SetContextMenu(c, r);
        }
 
        void r_Opened(object sender, RoutedEventArgs e)
        {
            c.Focus();
        }
 
        RadContextMenu BuildMenu()
        {
            RadContextMenu theMenu = new RadContextMenu();
 
            RadMenuItem mia = new RadMenuItem();
            mia.Header = "Item1";
           
            RadMenuItem mib = new RadMenuItem();
            mib.Header = "Item2";
 
            RadMenuItem mic = new RadMenuItem();
            mic.Header = "Item3";
 
            RadMenuItem copyItem = new RadMenuItem();
            copyItem.Header = "Copy";
 
            RadMenuItem pasteitem = new RadMenuItem();
            pasteitem.Header = "Paste";
 
            theMenu.Items.Add(mia);
            theMenu.Items.Add(mib);
            theMenu.Items.Add(mic);
            theMenu.Items.Add(copyItem);
            theMenu.Items.Add(pasteitem);
 
            return theMenu;
        }
    }
}


Thanks,
Abhi



0
Rosen Vladimirov
Telerik team
answered on 22 Jan 2013, 01:55 PM
Hello Abhi,

One way to achieve this is to modify the template of RadComboBoxItem and use TextBlock in it. TextBlock has SelectedText property that holds the data you need. To illustrate this I've prepared a simple application based on your code. You can find it attached and use it for your reference.

Greetings,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Abhi
Top achievements
Rank 1
answered on 23 Jan 2013, 06:02 AM
Hi Rosen,
                 Thanks I got it.....
0
Abhi
Top achievements
Rank 1
answered on 21 Feb 2013, 11:12 AM
Hi Rosen,
                 how to find which element has lost focus in silverlight...

Thanks,
Abhinandan
Tags
Menu
Asked by
Abhi
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Abhi
Top achievements
Rank 1
Share this question
or