I've a simple window which includes 2 fields :
<TextBox Grid.Column="1" HorizontalAlignment="Left" Height="21" Margin="10,25,0,0" Grid.Row="1" Name="textbox_login" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="227" KeyDown="textbox_login_KeyDown"/>
<PasswordBox Grid.Column="1" HorizontalAlignment="Left" Height="22" Margin="10,25,0,0" Grid.Row="2" Name="passwordBox_mdp" VerticalAlignment="Top" Width="227" KeyDown="passwordBox_mdp_KeyDown"/>
When I press the tab key on my keyboard I can switch to the next field but once I've reached the last field if I press the key again I have an exception on "MyApplication.Run" :
System.InvalidOperationException : Targettype button does not correspond to Control Element
Stacktrace : System.Windows.Style.CheckTargetType(Object element)
This error happens on all my windows/UC even if there isn't any field (just textblocks)
I don't know at all how to solve this.
I was getting a similar error in a modal dialog. To debug, I added a PreviewLostKeyboardFocus event handler to the dialog. Examining the KeyboardFocusChangedEventArgs NewFocus property told me which control the focus change was hitting a problem on.
For me it occurred when tabbing from a close Button to a TabItem in the dialog. To work around the issue I set KeyboardNavigation.IsTabStop="false" on the TabItem so that hitting the tab key would ignore the TabItem when changing focus. My TabItem looked like this:
<TabItem Name="MyTab" Header="Test Header" VerticalContentAlignment="Stretch"
VerticalAlignment="Stretch" Height="Auto" KeyboardNavigation.IsTabStop="False">
There's probably a better solution, but this prevents the exception.
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.