none
Stop DocumentViewer and Ribbon control from receiving Tab focus.(isTabStop = false not working)

    Question

  • Hello

     

    How can I stop my controls from receiving tab focus when I cycle through my controls using the TAB key i.e when tabbing ,the specified control should be skipped?

    I have already tried using the isTabStop = false ,but this is not working.

     

    I have a WPF window.xaml which has a Ribbon control and a DocumentViewer control apart from other controls like buttons,textboxes etc.I dont want the RibbonControl and the DocumentViewer to receive tab focus.I havnt even specified the TabIndex property for these two controls and have set isTabStop = false.This is not working.When I Tab through my page,not only do these controls receive the tab focus,it also seems to disrupt the tabbing order for the other controls.

     

    Thanks

     

     

     

     

    Monday, August 27, 2007 6:09 PM

Answers

  • Hi,

    I found a way to do this.

    Just need to set

    KeyboardNavigation.TabNavigation="Cycle"

     

    Thanks,

     

     

     

    Friday, September 07, 2007 10:07 PM

All replies

  • Hi,

    I found a way to do this.

    Just need to set

    KeyboardNavigation.TabNavigation="Cycle"

     

    Thanks,

     

     

     

    Friday, September 07, 2007 10:07 PM
  • HI,

    I am also facing the same issue.I am using a Ribbon Window and by tabbing the controls in the ribbon should not get focus.The focus should remain in the remaing part of the window only.I tried by setting the

    KeyboardNavigation.TabNavigation

    ="Cycle" as u mentioned for all the controlas in the ribbon window.But it didn't work for me.

    Ribbon application icon is getting focused and focus is not moving form that by tabbing.

    Please post some sample code which is working,it would be of great help.

    Thanks in advance.

    Monday, May 21, 2012 9:31 AM
  • You need to place the KeyboardNavigation.TabNavigation="Cycle" code in the parent Element of the document tree that you DO want to allow tabbing.

    eg:

    <StackPanel>
      <Ribbon ..../>
      <DockPanel KeyboardNavigation.TabNavigation="Cycle"..>
        ...
      </DockPanel>
    </StackPanel>

    Hope that helps

    Lee


    Lee Campbell http://LeeCampbell.blogspot.com

    Monday, May 21, 2012 10:28 AM
  • Hi,

    I tried to follow as you mentioned but it didn't help me out.Could you please correct me.Here is the XAML

    <ribbon:RibbonWindow x:Class="RibbonTestApplication.RibbonWindow1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
            Title="RibbonWindow1" 
            x:Name="Window"
            Width="640" Height="480">
        <Grid x:Name="LayoutRoot">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
            <ribbon:Ribbon x:Name="Ribbon" KeyDown="Ribbon_KeyDown" GotFocus="Ribbon_GotFocus"  KeyboardNavigation.TabNavigation="Cycle">
                <ribbon:RibbonTab x:Name="HomeTab" KeyTip="H"
                                  Header="Home" IsTabStop="False">
                    <ribbon:RibbonGroup x:Name="Group1" 
                                        Header="Group1" IsTabStop="False">
                        <ribbon:RibbonButton Label="A" KeyTip="a"  IsTabStop="False"/>
                        <ribbon:RibbonButton Label="B" KeyTip="b"   IsTabStop="False"/>
                        <ribbon:RibbonButton Name="c" Label="C" KeyTip="c"  IsTabStop="False"/>
                    </ribbon:RibbonGroup>
              
            </ribbon:Ribbon>
            <Button Content="Button1" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="123,81,0,0" Name="button1" VerticalAlignment="Top" Width="75" TabIndex="2" KeyboardNavigation.TabNavigation="Cycle"/>
            <Button Content="Button2" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="313,81,0,0" Name="button2" VerticalAlignment="Top" Width="75" TabIndex="1" KeyboardNavigation.TabNavigation="Cycle"/>
            <ComboBox Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="62,33,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" TabIndex="0" KeyboardNavigation.TabNavigation="Cycle"/>
        </Grid>
    </ribbon:RibbonWindow>

    Here is the .cs

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using Microsoft.Windows.Controls.Ribbon; namespace RibbonTestApplication { /// <summary> /// Interaction logic for RibbonWindow1.xaml /// </summary> public partial class RibbonWindow1 : RibbonWindow { public RibbonWindow1() { InitializeComponent(); // Insert code required on object creation below this point. } private void Ribbon_KeyDown(object sender, KeyEventArgs e) { // when tab key is pressed tried change the focus // but it is not working if (c.IsFocused == true) { if (Key.Tab == e.Key) { button1.Focus(); } } } private void Ribbon_GotFocus(object sender, RoutedEventArgs e) { //just tried to change the focus when ribbon got focus // it is working and the focus is changing but Shift+tab it wont work and in future if controls order changes we need to change the code here(So I think this is not the correct way) // comboBox1.Focus(); } } }

    When Tab is pressed, the focus should rotate in the window's controls and should not enter the ribbon.

    Thanks in advance



    Lavanya


    Monday, May 21, 2012 1:15 PM
  • I think what you need to do is:

    <ribbon:RibbonWindow x:Class="RibbonTestApplication.RibbonWindow1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
            Title="RibbonWindow1" 
            x:Name="Window"
            Width="640" Height="480">
        <DockPanel>
    
            <ribbon:Ribbon x:Name="Ribbon" DockPanel.Dock="Top" KeyDown="Ribbon_KeyDown" GotFocus="Ribbon_GotFocus"  KeyboardNavigation.TabNavigation="Cycle">
                <ribbon:RibbonTab x:Name="HomeTab" KeyTip="H"
                                  Header="Home" IsTabStop="False">
                    <ribbon:RibbonGroup x:Name="Group1" 
                                        Header="Group1" IsTabStop="False">
                        <ribbon:RibbonButton Label="A" KeyTip="a"  IsTabStop="False"/>
                        <ribbon:RibbonButton Label="B" KeyTip="b"   IsTabStop="False"/>
                        <ribbon:RibbonButton Name="c" Label="C" KeyTip="c"  IsTabStop="False"/>
                    </ribbon:RibbonGroup>
              
            </ribbon:Ribbon>
    		<StackPanel Orientation="Horizontal"
    					KeyboardNavigation.TabNavigation="Cycle">
    			<Button x:Name="button1" Content="Button1" Height="23" Width="75" TabIndex="2" />
    			<Button x:Name="button2" Content="Button2" Height="23" Width="75" TabIndex="1"/>
    			<ComboBox x:Name="comboBox1" Height="23" Width="120" TabIndex="0" />
    		</StackPanel>
    	</DockPanel>
    </ribbon:RibbonWindow>

    I just needed to get rid of the single grid, as I need to scope the buttons that can have focus separately to the ribbon.


    Lee Campbell http://LeeCampbell.blogspot.com

    Monday, May 21, 2012 5:12 PM
  • Hi,

    When the window is launched the focus is on the ribbon and it not coming out by tabbing.When I explicitly set the focus to the controls in the stackpanel it is working as expected.Is there any way to change the default focus or changing the focus by tabbing from ribbon to the controls outside ribbon.

    Thanks for the quick response.


    Lavanya

    Tuesday, May 22, 2012 4:56 AM
  • <ribbon:RibbonWindow x:Class="RibbonTestApplication.RibbonWindow1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
            Title="RibbonWindow1" 
            x:Name="Window"
            FocusManager.FocusedElement="{Binding ElementName=ButtonPanel}"
            Width="640" Height="480">
        <DockPanel>
    
            <ribbon:Ribbon x:Name="Ribbon" DockPanel.Dock="Top" KeyDown="Ribbon_KeyDown" GotFocus="Ribbon_GotFocus"  KeyboardNavigation.TabNavigation="Cycle">
                <ribbon:RibbonTab x:Name="HomeTab" KeyTip="H"
                                  Header="Home" IsTabStop="False">
                    <ribbon:RibbonGroup x:Name="Group1" 
                                        Header="Group1" IsTabStop="False">
                        <ribbon:RibbonButton Label="A" KeyTip="a"  IsTabStop="False"/>
                        <ribbon:RibbonButton Label="B" KeyTip="b"   IsTabStop="False"/>
                        <ribbon:RibbonButton Name="c" Label="C" KeyTip="c"  IsTabStop="False"/>
                    </ribbon:RibbonGroup>
              
            </ribbon:Ribbon>
    		<StackPanel x:Name="ButtonPanel" Orientation="Horizontal"
    					KeyboardNavigation.TabNavigation="Cycle">
    			<Button x:Name="button1" Content="Button1" Height="23" Width="75" TabIndex="2" />
    			<Button x:Name="button2" Content="Button2" Height="23" Width="75" TabIndex="1"/>
    			<ComboBox x:Name="comboBox1" Height="23" Width="120" TabIndex="0" />
    		</StackPanel>
    	</DockPanel>
    </ribbon:RibbonWindow>
    Add the FocusManager.FocusedElement="..." code is as per above.

    Lee Campbell http://LeeCampbell.blogspot.com

    Tuesday, May 22, 2012 10:10 AM
  • It sounds as it works but it is not working


    Lavanya

    Tuesday, May 22, 2012 10:24 AM