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

RadMenuItemAutomationPeer causing tabbing issues

4 Answers 99 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Teddy Stotis
Top achievements
Rank 1
Teddy Stotis asked on 18 Mar 2011, 10:02 PM
I have a menu item with StaysOpenOnClick set and two textboxes in it as well.  On hitting Enter on either of the text boxes, I need to close the menu, but since StaysOpenOnClick is set, I can't use RadMenuItemAutomationPeer's Invoke method on the menu item with the two text boxes, so I call it on it's parent menu, which closes the submenu but what happens is that the tabbing location of the application is reset and that menu item that I called Invoke on stays highlighted until I mouse over it.

Here's the template for the dual text box menu item:
<telerik:HierarchicalDataTemplate x:Key="CustomRangeItemTemplate"
                  ItemsSource="{Binding Items}"
                  telerik:ContainerBinding.ContainerBindings="{StaticResource DataItemBindings}">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Text}" Foreground="Gray" Margin="0,0,5,0"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="From:" Foreground="Gray"/>
<TextBox x:Name="txtFrom" Width="75"
     Text="{Binding From, Mode=TwoWay,
  NotifyOnValidationError=True, ValidatesOnExceptions=True,
  UpdateSourceTrigger=Explicit}"
    GotFocus="OnClick" KeyDown="OnKeyDown"
    LostFocus="OnFromLostFocus" Loaded="OnFromLoaded"/>
<TextBlock Text="To:" Foreground="Gray"/>
<TextBox x:Name="txtTo" Width="75"
     Text="{Binding ToStrikeBindingMember, Mode=TwoWay,
  NotifyOnValidationError=True, ValidatesOnExceptions=True,
  UpdateSourceTrigger=Explicit}"
     GotFocus="OnClick" KeyDown="OnKeyDown"
     LostFocus="OnToLostFocus" Loaded="OnToLoaded"/>
</StackPanel>               
</StackPanel>
</telerik:HierarchicalDataTemplate>

StaysOpenOnClick is set by the ContainerBindings.
Here's the template for the parent menu:
<telerik:HierarchicalDataTemplate x:Key="MenuItemTemplate"
                  ItemsSource="{Binding Items}"
                  telerik:ContainerBinding.ContainerBindings="{StaticResource DataItemBindings}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding PrecedingText}" Foreground="Gray"/>
<TextBlock Text="{Binding Text}" />
</StackPanel>
</telerik:HierarchicalDataTemplate>

Here's the menu's declaration:
<telerikNavigation:RadMenu x:Name="Menu"
    ItemClick="OnRadMenuItemClick"
    ClickToOpen="True" Margin="1,0,1,0"
    HorizontalAlignment="Stretch" VerticalAlignment="Center"
    ItemTemplateSelector="{StaticResource MenuTemplateSelector}"
    ItemsSource="{Binding Items}"/>

And here's the code that calls the Invoke method (note, in my implementation, I have a single menu item bound to the menu, and that has all the sub menu items)
RadMenuItem rootMenuItem = menu.ItemContainerGenerator.ContainerFromIndex(0) as RadMenuItem;
 
RadMenuItemAutomationPeer mip = new RadMenuItemAutomationPeer(rootMenuItem);
mip.Invoke();

So, is this a known issue, or am I just doing this wrong.  Is there an easier way to close a submenu and/or entire menu without any sort of highlighting issues or tab resetting issues.

4 Answers, 1 is accepted

Sort by
0
Teddy Stotis
Top achievements
Rank 1
answered on 21 Mar 2011, 02:29 PM
I even just tried this:

RadMenuItem rootMenuItem = menu.ItemContainerGenerator.ContainerFromIndex(0) as RadMenuItem;
RadMenuItem menuItem = rootMenuItem.ItemContainerGenerator.ContainerFromItem(rootMenuItem.Items[5]) as RadMenuItem;
  
menuItem.StaysOpenOnClick = false;
RadMenuItemAutomationPeer mip = new RadMenuItemAutomationPeer(menuItem);
mip.Invoke();
menuItem.StaysOpenOnClick = true;

So, I temporarily reset the StaysOpenOnClick flag on the menu item with the two text boxes and call the Invoke on it's RadMenuItemAutomationPeer, but I still get the issue with the highlight style stuck on the menu, and the tabbing reset.
0
Hristo
Telerik team
answered on 21 Mar 2011, 09:51 PM
Hello Teddy,

RadMenuItemAutomationPeer implements IExpandCollapseProvider so you could call Collapse method to close the menu and Expand method to open it instead of Invoke method which fires click event.

Let us know if this helps you.

Best wishes,
Hristo
the Telerik team
0
Teddy Stotis
Top achievements
Rank 1
answered on 21 Mar 2011, 10:09 PM

Calling Collapse instead of Invoke didn't help.

I solved the tabbing issue by listening on the SubmenuClosed event of the radmenuitem and in there, I added the following code to give the menu focus:

HtmlPage.Plugin.Focus();
(sender as RadMenuItem).Focus();

But the Highlighted state of the menu still stays until I mouse over and out of it.
0
Hristo
Telerik team
answered on 23 Mar 2011, 10:16 AM
Hello Teddy,

I'm attaching a project that demonstrate how to Expand/Collapse menu using RadMenuItemAutomationPeer.
All menu items have StaysOpenOnClick=True.

I don't see problems with Highlight or Focus of Silverlight plug-in.

Let me know if you need more information.

Regards,
Hristo
the Telerik team
Tags
Menu
Asked by
Teddy Stotis
Top achievements
Rank 1
Answers by
Teddy Stotis
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or