问题
I'm using the new SearchBox Control in my Windows 8.1 app, but everytime I launch the app the SearchBox has the focus and displays the search history. I've tried to set the focus on another control on my page, but it doesn't work. So how can I start my app without showing the search history?
Thanks.
回答1:
Here's my guess. You are attempting to set focus to something else on the page, but there's actually nothing else on your page that can accept a programmatic focus. To test this, simply add a <Button />
to your page and set the focus to that. Buttons are perfect for this test, as would be a <TextBox />
. If this foxes the problem then you understand it.
You have some options, and your choices will vary based on your app:
- Set the SearchBox to IsEnabled=false until the Page.Loaded is raised
- Set focus on another control, like a
<Button />
that is Width="1" and Height="1" - You might try TabStop="False" on the SearchBox, but that may not work
- Move the SearchBox further down the Logical Tree, the default Tab Stop is higher
Sorry for just brainstorming with you on this. I bet one of those will do it. Let me know.
Best of luck.
回答2:
Try setting the SearchHistoryEnabled to false: http://msdn.microsoft.com/en-US/library/windows/apps/windows.ui.xaml.controls.searchbox.searchhistoryenabled.aspx
来源:https://stackoverflow.com/questions/20544627/searchboxcontrol-has-focus-on-app-launching-on-win8-1