如何在WPF中将键盘选项卡选择设置为特定控件 [英] how to set keyboard tab selection to a particular control in WPF
问题描述
我有两个文本框和两个按钮......我在第一个文本框Lost Focus事件中写了一些逻辑。一旦我点击键盘标签光标将在第二个文本框闪烁..现在我想选择按钮1或按钮2而不是第二个文本框。我怎么能实现这个...任何想法......建议。
我在第一篇文章末尾添加box LostFocus活动
Keyboard.Focus(btnName);
FocusManager.SetFocusedElement( this ,btnName);
这两个不起作用
提前谢谢
set< Button Name =btnKeyboardNavigation.TabIndex =0/>
接下来你可以设置哪个控件需要在按下键盘标签键后立即导航
<按钮名称=btn1KeyboardNavigation.TabIndex =1/> ;
通过在xaml中设置我解决了我的问题
嗨我的朋友。我创建了一个包含控件的小例子。
你是对的。我认为这种行为是因为Control.Property优先。
你必须写入xaml:
< 网格 >
< TextBox 高度 = 23 宽度 = 80 HorizontalAlignment = 左 LostFocus = TextBox_LostFocus / >
< TextBox 高度 = 23 宽度 = 80 HorizontalAlignment = 左 保证金 = 100 80 0 0 KeyboardNavigation.IsTabStop = False / >
< 按钮 x:名称 = myButton 内容 = first 高度 = 23 宽度 = 80 VerticalAlignment = 热门 / > ;
< 按钮 内容 = second 高度 = 23 宽度 = 80 VerticalAlignment = 中心 / < span class =code-keyword>>
< / Grid >
和你的代码求得:
private void TextBox_LostFocus(< span class =code-keyword> object sender,RoutedEventArgs e)
{
// 你的逻辑
myButton.Focus();
}
查看这个..
System.Threading.ThreadPool.QueueUserWorkItem(
(a)= >
{
btnName.Dispatcher.Invoke(
new 行动(()= >
{
bnnName.Focus();
}));
}
);
来源:
http://stackoverflow.com/问题/ 673536 /倾斜设置聚焦到一个胎化的-用户控件
I have two text boxes and two buttons...I had written some logic in first text box Lost Focus event.As soon as i click the keyboard tab cursor will blink at second text box..Now i want to select the button 1 or button 2 instead of second text box.How can i achieve this...any idea...suggestion.
I added at the end of first text box LostFocus event
Keyboard.Focus(btnName);
FocusManager.SetFocusedElement(this, btnName);
these two didn't work
Thanks in advance
set<Button Name="btn" KeyboardNavigation.TabIndex="0"/>
next u can set which control need to navigate as soon as your press keyboard tab key
<Button Name="btn1" KeyboardNavigation.TabIndex="1"/>
by setting in xaml i solved my problem
Hi my friend. i create a small example that contains your controls.
you are right. i think this behavior is because of Control.Property precedeny.
and you must write into xaml:
<Grid> <TextBox Height="23" Width="80" HorizontalAlignment="Left" LostFocus="TextBox_LostFocus"/> <TextBox Height="23" Width="80" HorizontalAlignment="Left" Margin="100 80 0 0" KeyboardNavigation.IsTabStop="False"/> <Button x:Name="myButton" Content="first" Height="23" Width="80" VerticalAlignment="Top"/> <Button Content="second" Height="23" Width="80" VerticalAlignment="Center"/> </Grid>
and your code begind:
private void TextBox_LostFocus(object sender, RoutedEventArgs e) { //your logic myButton.Focus(); }
check this one..
System.Threading.ThreadPool.QueueUserWorkItem( (a) => { btnName.Dispatcher.Invoke( new Action(() => { btnName.Focus(); })); } );
source:
http://stackoverflow.com/questions/673536/cant-set-focus-to-a-child-of-usercontrol
这篇关于如何在WPF中将键盘选项卡选择设置为特定控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!