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

TextBlock Selected Text With ContextMenu

4 Answers 244 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Lee asked on 16 Apr 2010, 12:33 PM
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.

4 Answers, 1 is accepted

Sort by
0
Accepted
Valeri Hristov
Telerik team
answered on 16 Apr 2010, 04:18 PM
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.
0
KodeKreachor
Top achievements
Rank 1
answered on 21 Apr 2010, 05:30 PM
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(); 
   }
}

 

 

0
Lee
Top achievements
Rank 1
answered on 22 Apr 2010, 12:42 PM
Thanks Eric, with a couple of modifications this was exactly what I was looking for.
0
KodeKreachor
Top achievements
Rank 1
answered on 22 Apr 2010, 04:07 PM
My pleasure, happy to help
Tags
Menu
Asked by
Lee
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
KodeKreachor
Top achievements
Rank 1
Lee
Top achievements
Rank 1
Share this question
or