locked
Tab Order of Controls in WPF RRS feed

  • Question

  • How to set the Tab Order of Controls in WPF.
    Just like we used to set the Tab Order in Visual C# Windows Form.
    I want to set the Tab Order of the controls which are placed on WPF Windows.
    Thanks in advance.
    Sunday, March 25, 2012 12:01 PM

Answers

  • Hi Amey,

    try setting the TabIndex property of controls in the ascending order.

    eg:-

     <Grid>
            <Button Content="Button" TabIndex="0" HorizontalAlignment="Left" Margin="238,93,0,0" VerticalAlignment="Top" Width="75"/>
            <Button Content="Button" TabIndex="1" HorizontalAlignment="Left" Margin="175,145,0,0" VerticalAlignment="Top" Width="75"/>
        </Grid>
    Thanks,

    Dexter

    • Proposed as answer by Asaf Benyamin Sunday, March 25, 2012 3:46 PM
    • Marked as answer by Amey Kelkar Sunday, March 25, 2012 6:12 PM
    Sunday, March 25, 2012 12:28 PM
  • And watch out for containers.

    You may want to set some to IsTabStop="False"

    • Marked as answer by Amey Kelkar Sunday, March 25, 2012 6:12 PM
    Sunday, March 25, 2012 4:02 PM

All replies

  • Hi Amey,

    try setting the TabIndex property of controls in the ascending order.

    eg:-

     <Grid>
            <Button Content="Button" TabIndex="0" HorizontalAlignment="Left" Margin="238,93,0,0" VerticalAlignment="Top" Width="75"/>
            <Button Content="Button" TabIndex="1" HorizontalAlignment="Left" Margin="175,145,0,0" VerticalAlignment="Top" Width="75"/>
        </Grid>
    Thanks,

    Dexter

    • Proposed as answer by Asaf Benyamin Sunday, March 25, 2012 3:46 PM
    • Marked as answer by Amey Kelkar Sunday, March 25, 2012 6:12 PM
    Sunday, March 25, 2012 12:28 PM
  • Hi Amey,

    you can also tab order in from Code Behind like below

    int i = 0;

    Button1.TabIndex = i++;

    Button2.TabIndex = i++;

    Button3.TabIndex = i++;

    TextBox1.TabIndex = i++;

    Regards

    Sophia

    Sunday, March 25, 2012 1:52 PM
  • And watch out for containers.

    You may want to set some to IsTabStop="False"

    • Marked as answer by Amey Kelkar Sunday, March 25, 2012 6:12 PM
    Sunday, March 25, 2012 4:02 PM
  • Thanks a lot for your quick reply!!
    But why is the default Tab Index of controls set to 2147483647 ?
    Because it is the largest possible int ?
    Sunday, March 25, 2012 6:15 PM
  • Yes, the TabIndex's default value is Int32.MaxValue.

    (http://msdn.microsoft.com/en-us/library/system.windows.controls.control.tabindex.aspx)

    --

    Matti

    Sunday, March 25, 2012 6:53 PM
  • Why is this not in the properties?
    Sunday, May 15, 2016 8:12 PM
  • It is in the properties of controls.TabIndex is under the Common grouping of properties.

    You can use the search box to find it if you're having trouble.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Monday, May 16, 2016 4:16 PM