gpt4 book ai didi

c# - 文本框已聚焦,但在我单击之前无法键入 - XAML/C#/WPF

转载 作者:行者123 更新时间:2023-12-04 02:55:45 25 4
gpt4 key购买 nike

我有一个有趣的情况,我使用以下方法将焦点设置在搜索框上:FocusManager.FocusedElement="{Binding ElementName=SearchBox}" 我在此处找到:Set the focus on a textbox in xaml wpf

好消息是搜索框实际上是聚焦的(我有一个触发器在聚焦时执行操作),但在单击文本框之前我无法在文本框中输入内容。

我的文本框非常基础:

<TextBox x:Name="SearchBox"
Grid.Row="0"
style="{StaticResource SearchBox}" />

知道如何让用户在打开控件时立即输入吗?

最佳答案

请参阅以下链接: https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.focusmanager.focusedelement?redirectedfrom=MSDN&view=netframework-4.7.2#System_Windows_Input_FocusManager_FocusedElement

特别是备注:

The FocusedElement is the element which has logical focus for a specific focus scope. This object may or may not have keyboard focus. Keyboard focus refers to the element that receives keyboard input. For more information on focus, keyboard focus, and logical focus, see the Input Overview.

和: https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.focusmanager?redirectedfrom=MSDN&view=netframework-4.7.2

An element with logical focus does not necessarily have keyboard focus, but an element with keyboard focus will have logical focus. It is possible to define a focus scope within a focus scope. In this case, both the parent focus scope and the child focus scope can have a FocusManager.FocusedElement

在下面的帖子中,您将找到一个如何处理此问题的示例: https://stackoverflow.com/a/20299923/9295125

关于c# - 文本框已聚焦,但在我单击之前无法键入 - XAML/C#/WPF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53161233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com