如何将TextBox集中在C#Metro应用程序的AppBar中?

时间:2012-03-18 14:47:36

标签: c# windows-runtime focus winrt-xaml appbar

我有以下代码:

<Page.BottomAppBar>
    <AppBar x:Name="MyAppBar" Height="32" IsOpen="True" Opened="MyAppBar_Opened">
        <TextBox x:Name="SearchBar" Grid.Row="2" KeyDown="SearchBar_KeyDown"/>
    </AppBar>
</Page.BottomAppBar>

问题是它在应用程序打开时没有焦点,当我右键单击两次以关闭并再次打开它时它也没有焦点。

我目前在MyAppBar_OpenedOnNavigatedTo中都有以下代码:

if (MyAppBar == null)
    return;

MyAppBar.Focus(Windows.UI.Xaml.FocusState.Keyboard);

if (SearchBar == null)
    return;

SearchBar.Focus(Windows.UI.Xaml.FocusState.Keyboard);

但这似乎没有任何效果,其他枚举值如MouseProgrammatic也不起作用。我做错了什么导致没有激活?

我知道之前曾经使用过的替代方案,但Metro FocusManager没有SetFocusedElement吗?

0 个答案:

没有答案