2

I have a window in which two contentcontrol, in which i'm loading the usercontrol at runtime, I need to set the tab order for the user controls in the ContentControl1 and ContentControl2? How can I achieve that?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Tanya
  • 1,571
  • 5
  • 22
  • 33
  • This is a duplicate of http://stackoverflow.com/questions/359758/setting-tab-order-in-wpf – Justin Pihony Mar 01 '12 at 05:26
  • i need to set the tab order for Controls in the UserControl which has been loaded at runtime.. i have already tried the solution given in that thread but its not working for me. – Tanya Mar 01 '12 at 05:38

2 Answers2

0

You can use KeyboardNavigation.TabNavigation and KeyboardNavigation.TabIndex to achieve this.

Example :

<ContentControl Content="{Binding Head}" x:Name="HeadCtrl" Height="50" ContentTemplate="{StaticResource VectorTemplate}"/>

 <DataTemplate x:Key="VectorTemplate">
    <StackPanel KeyboardNavigation.TabNavigation="Local" KeyboardNavigation.TabIndex="-1">
         <Button Content="{Binding Path=X}" KeyboardNavigation.TabIndex="0" ></Button>
         <Button Content="{Binding Path=Y}" KeyboardNavigation.TabIndex="1" ></Button>
    </StackPanel>
 </DataTemplate>
Avani Vadera
  • 526
  • 3
  • 7
  • But i'm having two content controls, i need to tab through both content controls. And the challenge is the contentcontrol1 is populated with a Usercontrol having textboxes at runtime and The content control2 is populated with buttons at compile time. I not using any datatemplate. I'm very new to WPF help me pls – Tanya Mar 01 '12 at 05:45
  • Are the number of textboxes in usercontrol constant? if yes then you can specify KeyboardNavigation.TabIndex while creating the textboxes and buttons. It could be in any form. The challenge would be if the number of your textboxes is dynamic – Avani Vadera Mar 01 '12 at 06:35
0

What I can understand is to set the Tab order of the usercontrol that you are adding at runtime. How about doing this:

 var usercontrol = new UserControl1();
 usercontrol.TabIndex = 0;
 ContentControl1.Content = usercontrol;
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Dipesh Bhatt
  • 827
  • 6
  • 11
  • ya.. but wht abt the textboxes inside the usercontrol? – Tanya Mar 01 '12 at 06:53
  • you can set it in usercontrol itself or give that textbox a Name in xaml e.g. and than you can set it from code also like usercontrol.myTextBox.TabIndex = 0; – Dipesh Bhatt Mar 01 '12 at 06:55