0
我在我的WPF應用程序中有幾個彈出窗口,它工作正常。vb.net wpf popup沒有焦點
但是,這最後一個不接受文本框中的焦點或輸入。我不明白爲什麼。
<Label x:Name="lblSearch" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="1" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,5" Height="30" Width="Auto">Search</Label>
<TextBox Name="txtSearch" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="1" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,5" Height="30" Width="200" IsReadOnly="False" IsEnabled="True"></TextBox>
<Button Name="btnSearch" Grid.Row="0" Grid.Column="2" Style="{StaticResource ButtonSmall}" Template="{DynamicResource BlackButton}" Margin="5">Search</Button>
<Label x:Name="lblReplace" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="1" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,5" Height="30" Width="Auto">Replace</Label>
<TextBox Name="txtReplace" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="1" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,5" Height="30" Width="200" IsReadOnly="False" IsEnabled="True"></TextBox>
<Button Name="btnReplace" Grid.Row="1" Grid.Column="2" Style="{StaticResource ButtonSmall}" Template="{DynamicResource BlackButton}" Margin="5">Replace</Button>
<Button Name="btnStopSearch" Grid.Row="2" Grid.Column="3" Style="{StaticResource ButtonSmall}" Template="{DynamicResource BlackButton}" Margin="5">Done</Button>
<DockPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
</DockPanel>
</local:GridEx>
</DockPanel>
</Border>
</Border>
</Popup>
我想這個代碼強制專注於它,但無濟於事:
Private searchWhere As String = Nothing
Private Sub txtTypeEditor_keyDown(sender As Object, e As Forms.KeyEventArgs) Handles txtTypeEditor.KeyDown
If e.KeyCode = Forms.Keys.F AndAlso e.Control AndAlso Not e.Alt AndAlso Not e.Shift Then
PopupSearch.IsOpen = True
txtSearch.Focus()
Keyboard.Focus(txtSearch)
searchWhere = "TypeEditor"
e.Handled = True
End If
End Sub
Private Sub Popup1_Opened(sender As Object, e As EventArgs) Handles PopupSearch.Opened
txtSearch.Focus()
Keyboard.Focus(txtSearch)
End Sub
看樣子txtTypeEditor保持在聚焦。任何想法如何模糊它?
我現在有一個解決方法:如果我通過聚焦另一個文本框來模糊文本框,那麼彈出框接受焦點。
但是,如果用戶單擊到txtTypeEditor文本框中,然後單擊彈出框中的輸入字段,則鼠標焦點切換到彈出窗口,但鍵盤焦點仍保留在文本框中。
我不知道如何檢查與按鍵 – Adder
CTRL-F鍵,你可以通過_keydown捕捉按CTRL並在處理程序中設置一個布爾值ctrl = true,然後在_keyPress中檢查「F」beeing按下並且ctrl = true – DonGru