简体   繁体   中英

how to set the Taborder for the usercontrols in the Content Control of WPF

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 to achieve that?

Regards, Tanya

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>

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM