RadContextMenu on Rightclick for Silverlight controls

14 posts, 0 answers
  1. Abhi
    Abhi avatar
    38 posts
    Member since:
    Nov 2012

    Posted 08 Jan 2013 Link to this post

    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........
  2. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 08 Jan 2013 Link to this post

    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.

  3. DevCraft banner
  4. Abhi
    Abhi avatar
    38 posts
    Member since:
    Nov 2012

    Posted 09 Jan 2013 Link to this post

    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

     

  5. Abhi
    Abhi avatar
    38 posts
    Member since:
    Nov 2012

    Posted 09 Jan 2013 Link to this post

    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..........

     

     

     

     

     

     

  6. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 10 Jan 2013 Link to this post

    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.

  7. Abhi
    Abhi avatar
    38 posts
    Member since:
    Nov 2012

    Posted 10 Jan 2013 Link to this post

    Hi,
            can u just give one sample for
           
            RadContextmenu with autocompletebox to provide cut, copy, paste fuctionality on rightclick on it.
  8. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 10 Jan 2013 Link to this post

    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.

  9. Abhi
    Abhi avatar
    38 posts
    Member since:
    Nov 2012

    Posted 15 Jan 2013 Link to this post

    thank you very much
    I got it..............
  10. Abhi
    Abhi avatar
    38 posts
    Member since:
    Nov 2012

    Posted 15 Jan 2013 Link to this post

    On Rightclick, RadcontextMenu is Opened but the selectedtext is no longer visible.........



  11. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 17 Jan 2013 Link to this post

    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.

  12. Abhi
    Abhi avatar
    38 posts
    Member since:
    Nov 2012

    Posted 18 Jan 2013 Link to this post

    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



  13. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 22 Jan 2013 Link to this post

    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.

  14. Abhi
    Abhi avatar
    38 posts
    Member since:
    Nov 2012

    Posted 23 Jan 2013 Link to this post

    Hi Rosen,
                     Thanks I got it.....
  15. Abhi
    Abhi avatar
    38 posts
    Member since:
    Nov 2012

    Posted 21 Feb 2013 Link to this post

    Hi Rosen,
                     how to find which element has lost focus in silverlight...

    Thanks,
    Abhinandan
Back to Top
DevCraft banner