RadMenuItemAutomationPeer causing tabbing issues

5 posts, 0 answers
  1. Teddy Stotis
    Teddy Stotis avatar
    4 posts
    Member since:
    Mar 2010

    Posted 18 Mar 2011 Link to this post

    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.
  2. Teddy Stotis
    Teddy Stotis avatar
    4 posts
    Member since:
    Mar 2010

    Posted 21 Mar 2011 Link to this post

    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.
  3. DevCraft banner
  4. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 21 Mar 2011 Link to this post

    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
  5. Teddy Stotis
    Teddy Stotis avatar
    4 posts
    Member since:
    Mar 2010

    Posted 21 Mar 2011 Link to this post

    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.
  6. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 23 Mar 2011 Link to this post

    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
Back to Top
DevCraft banner