我正在尝试让 UserControl 正确地进行选项卡并感到困惑。逻辑树看起来像这样。
|-Window
-Grid
-TabControl
-TabItem
-StackPanel
-MyUserControl
|-StackPanel
-GroupBox
-Grid
-ComboBox
-Textbox1
-Textbox2
Run Code Online (Sandbox Code Playgroud)
Everything works fine, except when the visibility converter for the ComboBox returns Visibility.Collapsed(don't allow user to change database mode), then when textbox1 is selected, instead of being able to tab through the controls in the UserControl, the focus shifts to a button在窗口底部声明。除了显示的控件之外,没有设置 TabIndex 或 FocusManager 属性。
我的头撞在砖墙上,我一定是遗漏了什么。我试过 IsFocusScope=True/False,用 FocusedElement 玩,如果 ComboBox 是不可见的 ( Visibility.Collapsed) ,没有任何效果。
<Window x:Class="MyNamespace.Client.WinInstaller"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FocusManager.FocusedElement="{Binding ElementName=tabWizard}">
<Window.Resources>
<props:Settings …Run Code Online (Sandbox Code Playgroud) 我有一个“主要”表格(form1)。在那个表单中,我成功地打开了另一个表单 ( form2) - 但是 - 当该表单打开时,您仍然可以控制底层表单 ( form1)。
我不希望用户能够这样做,每当他试图点击它或其他东西时,弹出的表单 ( form2) 应该获得焦点/闪烁,并带有一些默认的 Windows 声音。我刚刚描述了如果弹出窗口是 FileSave/OpenDialog 时它的行为。这些对话框完全按照我希望的方式工作。
我试过设置,form2.Owner = form1;但没有达到预期的效果。
所以我的问题基本上是:我怎样才能获得相同的焦点/等效果。在表单上 - 它在 Save/OpenDialog 上如何?
谢谢,
~ Tgys
我想在使用SWING的游戏中添加键盘快捷键.到目前为止,我一直在使用以下代码:
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addKeyEventDispatcher(new KeyEventDispatcher() {
@Override
public boolean dispatchKeyEvent(KeyEvent e) { ... }
Run Code Online (Sandbox Code Playgroud)
出于测试目的,我想创建此应用程序的两个实例(测试网络播放).问题是当我使用热键时,非聚焦窗口会抓住焦点.(稍后创建的窗口.)
我怀疑问题是这样的
KeyboardFocusManager.getCurrentKeyboardFocusManager()
Run Code Online (Sandbox Code Playgroud)
是一个静态方法(两个实例都是从同一个JVM启动的).
我唯一想到的另一个选择是让每个组件将他们的键事件委托给祖先JFrame,并在一个地方处理它们,但这会涉及很多锅炉代码,我认为这将是一个丑陋的解.
此外,在正常的游戏过程中不会出现问题,它只会让我在测试时烦恼.
I have the following Javascript/jQuery code that focuses on an input field.
window.addEventListener("keydown",function (e) {
if (e.keyCode === 114 || (e.ctrlKey && e.keyCode === 70)) {
e.preventDefault();
$('#search').focus();
}
})
Run Code Online (Sandbox Code Playgroud)
However I want to make it that so that if the user presses Ctrl+F again after being in focus of the search field, it would open up the default browser search window.
My idea was to change the code to:
window.addEventListener("keydown",function (e) {
if (e.keyCode === 114 || (e.ctrlKey && …Run Code Online (Sandbox Code Playgroud) 我正在使用 PySide 并且我有一个 QListWidget。我制作了一个虚拟项目并将其放置在 QListWidget 的顶部。我这样做是为了当该工具首次打开时,默认情况下不会选择任何有用的项目。我不喜欢这个空项目被“突出显示”,向用户展示该项目。我怎样才能摆脱这个轮廓/突出显示?我将附上该问题的图片:
我有一个输入标签,当我按下转义键时,我希望输入元素上的焦点消失,这意味着不再有文本光标或任何焦点样式(当用户输入时,他们的输入不会进入输入标签)。
下面的代码是我尝试实现上述功能的尝试,但它没有按预期工作。我想让这段代码按预期工作。
import React, { useRef } from 'react';
const onEscape = function (action) {
window && window.addEventListener('keydown', (e) => {
if (e.key === "Escape") {
action();
};
});
};
const MyComponent = () => {
...
const descRef = useRef();
onEscape(() => {
descRef.blur();
});
return (
<div>
<input
ref={descRef}
...
/>
</div>
);
};
Run Code Online (Sandbox Code Playgroud)
我已经测试了该onEscape函数,并且在将其他操作传递给它时它可以工作(当用户按下转义键时,它会执行传递给 onEscape 函数的任何函数)
我有一个像 Facebook 这样的应用程序(iOS7),菜单滑动并在右侧幻灯片上进行搜索。\n我想要的是当被viewDidLoad调用时,将焦点设置在UITextField搜索栏上并显示键盘。
我\xe2\x80\x99已经尝试过以下操作:
\n\nfor (id object in [[self.searchDisplayController searchBar] subviews])\n{\n for (id subObject in [object subviews])\n {\n if ([subObject isKindOfClass:[UITextField class]])\n {\n UITextField *textfield=(UITextField*)subObject;\n [textfield becomeFirstResponder];\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n但没有成功。
\n\n有任何想法吗?
\n我有ComboBox如下:
<ComboBox IsEditable="True"
Width="200"
Height="25"
IsTextSearchEnabled="False"
x:Name="cb"
PreviewTextInput="Cb_OnPreviewTextInput"
ItemsSource="{Binding ItemList}"
Text="{Binding SearchTextText}">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
什么时候Cb_OnPreviewTextInput叫我定IsDropdownOpen = true。在第一次尝试中(输入第一个字母后),选择了列表中的第一项,我可以使用相关箭头上下移动,插入符号仍然在TextBox.
当我继续打字时,我无法再上下导航(一次 1 项);此时,整个 ScrollViewer 获得焦点,我只能转到底部或顶部,但不能一一对应。我必须关闭弹出窗口,例如按 Escape 键,然后通过键入 1 个字符重新打开才能向上移动/再次下降。
我还注意到,按 PageUp 后,第一个项目也会被选中,所以我尝试在代码中模仿,但没有成功。
有谁知道在这里该怎么做才能顺利向上/向下导航和打字?
我正在开发一个webapp,我遇到了JavaScript问题.
以下是导致问题的HTML的简化版本.我有一些嵌套contenteditable divs(我用占位符文本替换了真实内容):
<div contenteditable="true" id="div1">
text
<div contenteditable="inherit" id="div2">
text
<div contenteditable="inherit" id="div3">
text
</div>
text
</div>
text
</div>
Run Code Online (Sandbox Code Playgroud)
我想通过JavaScript获取所选元素(由用户编辑),但到目前为止我还没有找到一种方法(成功).
我尝试了什么,为什么它不起作用:
我尝试过使用document.activeElement,它应该返回焦点中的任何一个元素.通常这是有效的,但在使用嵌套contenteditable元素时它不会产生所需的结果.它返回最上面的contenteditable祖先,而不是返回用户正在编辑的元素.
例如,如果div2选择/正在编辑,则document.activeElement返回div1.如果div3选择/正在编辑,document.activeElement也会返回div1.
所以我想document.activeElement这不是正确的方法.
如何获得正在编辑的最具体元素,而不是其最重要的contenteditable祖先?