How to set focus on NumericUpDown control?

≯℡__Kan透↙ 提交于 2019-12-24 05:53:54

问题


I am trying to set focus on NumericUpDown element from WPFs extended toolkit.
I heve following XAML

<Window ... 
    xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
<Grid>
    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal" FocusManager.IsFocusScope="True">
        <extToolkit:NumericUpDown HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="ItemsCount" Value="1"/>
        <TextBlock Text="XXX" Margin='10,0,0,0'/>
    </StackPanel>        
</Grid>
</Window>

I called Keyboard.Focus(ItemsCount) and ItemsCount.Focus() from constructor and from Loaded event with no success.
Control is getting focus when I press Tab, but in my case it is not acceptable.
I didn't found enything on google as well.
Is there any way to focus NumericUpDown?

P.S.
Calling Focus() works for TextBox so it's must be control specific issue.


回答1:


Maybe it is not set to be focusable, have you checked the value of Focusable?




回答2:


Set the SelectAllOnGotFocus property to True




回答3:


NumericUpDown1.Select(0, 1)    

'Set Tabstop to 1 'Initialize NumericUpDown1 with a single numeric value (i.e. "1").



来源:https://stackoverflow.com/questions/7050559/how-to-set-focus-on-numericupdown-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!