我有一個WPF中的視圖,我一直在爭取讓Tab鍵順序正確。我有三個文本框(讓我們稱它們爲Text1,Text2和Text3)以及兩個自定義控件,每個自定義控件都有幾個其他文本框和各種控件(讓它們稱爲Custom1和Custom2)。WPF標籤順序工作出錯
佈局是這樣的標籤流應該去Text1,Text2,Custom1,Custom2,Text3。我在每個控件上設置了TabIndex屬性以匹配此排序,並驗證它們全部都設置爲IsTabStop。
問題是,實際的選項卡流程是Text1,Text2,Text3,然後是Custom1,Custom2,我找不到原因。當它進入自定義控件時,它會像我期望的那樣正確地逐步控制它們中的每個控件。在第一個自定義控件出現之前,我無法弄清楚爲什麼會出現在第三個文本框中。
我已經嘗試了所有我能想到的方法,包括確保所有xaml元素都按標籤順序排列,但似乎沒有任何幫助。
我懷疑它將重點放在任何自定義控件之前將其所有的基本控件都考慮在內,但我沒有想法。任何幫助都會很棒。
編輯: 這是我的XAML:
<Grid>
<GroupBox x:Name="_groupBox" BorderBrush="Transparent" BorderThickness="0">
<Grid x:Name="_card">
<Label Content="A:" Height="28" HorizontalAlignment="Left" Margin="5,3,0,0" Name="_labelA" VerticalAlignment="Top" />
<Label Content="B:" Height="28" HorizontalAlignment="Left" Margin="5,25,0,0" Name="_labelB" VerticalAlignment="Top" />
<TextBox Name="_a" Height="20" HorizontalAlignment="Left" Text="{Binding AText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding AEnabled}" Margin="94,5,0,0" VerticalAlignment="Top" LostFocus="InputNameLeave" Width="221" TabIndex="0" />
<TextBox Name="_b" Height="20" HorizontalAlignment="Left" Margin="94,26,0,0" Text="{Binding BText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="102" TabIndex="1" />
<my:CustomControlA HorizontalAlignment="Left" Margin="-6,55,0,0" x:Name="_custom1" VerticalAlignment="Top" TabIndex="2" IsTabStop="True" />
<my:CustomControlB HorizontalAlignment="Left" Margin="334,0,0,0" x:Name="_custom2" VerticalAlignment="Top" Width="320" TabIndex="3" IsTabStop="True" />
<Label Content="C:" Height="28" HorizontalAlignment="Left" Margin="342,59,0,0" Name="_labelC" VerticalAlignment="Top" />
<TextBox Name="_c" Height="20" HorizontalAlignment="Left" Margin="417,60,0,0" Text="{Binding CText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding CEnabled}" VerticalAlignment="Top" Width="154" TabIndex="4" />
</Grid>
</GroupBox>
</Grid>
你可以發表你的XAML? – Rachel 2011-04-05 18:06:34