2009-12-11 10 views
4

J'ai une fenêtre simple avec un contrôle composite simple intégré dedans.WPF TabIndex dans une commande composite

(fenêtre principale)

<Window x:Class="TabOrder.Window1" 
xmlns:local="clr-namespace:TabOrder" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Title="Window1" Height="300" Width="300"> 
<Grid> 
    <Label HorizontalAlignment="Left" VerticalAlignment="Top">First</Label> 
    <TextBox TabIndex="0" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="80,0,0,0"/> 

    <Label HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,30,0,0">Second</Label> 
    <TextBox TabIndex="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="80,30,0,0"/> 

    <local:MyControl Margin="0,60,0,0" VerticalAlignment="Top" HorizontalAlignment="Stretch" TabIndex="2"/> 
</Grid> 

(contrôle composite)

<UserControl x:Class="TabOrder.MyControl" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
<Grid> 
    <Label HorizontalAlignment="Left" VerticalAlignment="Top">Third</Label> 
    <TextBox HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="80,0,0,0"/> 

    <Label HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,30,0,0">Fourth</Label> 
    <TextBox HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="80,30,0,0"/> 
</Grid> 

Comme prévu sur ma forme, je reçois 4 zones de texte ...

  • Première
  • Deuxième
  • Troisième
  • Quatrième

Mais quand "d'abord" a le focus et je frappe l'onglet mise au point est réglé sur "troisième". WPF semble voir la liste d'onglets comme une simple liste plate plutôt que comme un arbre où MyControl est TabIndex 3 et la zone de texte "Third" le premier contrôle à onglets dedans.

Est-ce un bug dans WPF ou existe-t-il un autre moyen de le faire? Le contrôle composite est utilisé dans de nombreuses fenêtres, il pourrait même être utilisé plus d'une fois sur une seule fenêtre.

Répondre

11

Je sais que cette réponse est assez tard ... mais avez-vous essayé:

<UserControl ... KeyboardNavigation.TabNavigation="Local"> 

Cela assurera une fois que votre UserControl a recieved focus, vous naviguerez que par ArrêtTabulation au sein de votre UserControl (au lieu de worring à propos des valeurs TabIndex conflictuelles dans votre application). Après la boucle à travers les TabStops de votre UserControl, TabNavigation reprendra à TabStop en dehors de celui-ci.

http://msdn.microsoft.com/en-us/library/system.windows.input.keyboardnavigationmode.aspx

+1

Il n'est pas trop tard pour moi. Merci. – zgnilec