TextBlock Selected Text With ContextMenu

5 posts, 1 answers
  1. Lee Weisenberger
    Lee Weisenberger avatar
    72 posts
    Member since:
    Nov 2009

    Posted 16 Apr 2010 Link to this post

    Hi, I'm trying to implement Copy and Paste context menu on TextBlocks and I have a question.

    When I select text in the TextBlock and right-click to bring up the context menu, the selected text is no longer visible.  Is there a way to have the selected text still show as selected when the context menu is displayed?

    Thanks.
  2. Answer
    Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 16 Apr 2010 Link to this post

    Hello Lee,

    I suppose that you are talking about TextBox controls, not TextBlock. The TextBox hides its selection when it has no focus. The menu items get the focus when they are displayed, hence the selection is not visible. Unfortunately you cannot change this behavior of the menu.

    Kind regards,
    Valeri Hristov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. KodeKreachor
    KodeKreachor avatar
    18 posts
    Member since:
    Jan 2008

    Posted 21 Apr 2010 Link to this post

    Try something like the following. I have textboxes inside of a RadGridView but the principle stands:

     

    public void RadContextMenu_Opened(object sender, RoutedEventArgs e)
    {
      
    RadContextMenu menu = (RadContextMenu)sender; 
      
    GridViewCell cell = menu.GetClickedElement<GridViewCell>(); 
      
    if (cell.Content.GetType().Equals(typeof(TextBox))) {
          ((
    TextBox)cell.Content).LostFocus += new RoutedEventHandler(CellTextBox_LostFocus);
          ((
    TextBox)cell.Content).Focus();
      
    }

    }

    void CellTextBox_LostFocus(object sender, RoutedEventArgs e)
    {
       ((
    TextBox)sender).LostFocus -= CellTextBox_LostFocus;
       ((
    TextBox)sender).Focus(); 
    }

    public void RadContextMenu_ItemClick(object sender, RadRoutedEventArgs e)
    {
      
    RadContextMenu menu = (RadContextMenu)sender; 
      
    GridViewCell cell = menu.GetClickedElement<GridViewCell>(); 
      
    if (cell.Content.GetType().Equals(typeof(TextBox))) {
          ((
    TextBox)cell.Content).Focus(); 
       }
    }

     

     

  5. Lee Weisenberger
    Lee Weisenberger avatar
    72 posts
    Member since:
    Nov 2009

    Posted 22 Apr 2010 Link to this post

    Thanks Eric, with a couple of modifications this was exactly what I was looking for.
  6. KodeKreachor
    KodeKreachor avatar
    18 posts
    Member since:
    Jan 2008

    Posted 22 Apr 2010 Link to this post

    My pleasure, happy to help
Back to Top
DevCraft banner