积极答复者
WPF里面textbox 在窗口启动时获取焦点,一定要逻辑里面实现吗?

问题
答案
-
你好,
你可以通过FocusManager.FocusedElement 附加属性 在XAML文件中实现焦点的设置。例如以下代码:
<StackPanel FocusManager.FocusedElement="{Binding ElementName=myTextBox}"> <TextBox>我是第一个TextBox</TextBox> <Button Click="bt_Click_1">Click Me!</Button> <TextBox Name="myTextBox" Text="取得焦点的TextBox" Background="AliceBlue" Focusable="True"/> </StackPanel>
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已建议为答案 Dummy yoyoModerator 2013年4月9日 7:20
- 已标记为答案 Lisa ZhuModerator 2013年4月15日 10:59
全部回复
-
你好,
你可以通过FocusManager.FocusedElement 附加属性 在XAML文件中实现焦点的设置。例如以下代码:
<StackPanel FocusManager.FocusedElement="{Binding ElementName=myTextBox}"> <TextBox>我是第一个TextBox</TextBox> <Button Click="bt_Click_1">Click Me!</Button> <TextBox Name="myTextBox" Text="取得焦点的TextBox" Background="AliceBlue" Focusable="True"/> </StackPanel>
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已建议为答案 Dummy yoyoModerator 2013年4月9日 7:20
- 已标记为答案 Lisa ZhuModerator 2013年4月15日 10:59