2016-11-21 1 views
1

Windows Store App의 경우 요구 사항은 "페이지가로드되고 사용자가 다른 구성 요소와 상호 작용 한 후에 TextBox에 포커스를 유지하십시오"입니다.Windows 8.1 TextBox 포커스 유지

페이지로드시와 사용자가 동일한 그리드 (즉, 버튼)의 다른 구성 요소와 상호 작용할 때 문제가 해결되었습니다.

MyTextBox.LostFocus += (s,e)=> { 
    Dispatcher.RunAsync(
      CoreDispatcherPriority.Normal,() => SearchBox.Focus(FocusState.Programmatic)); 
} 

사용자가 AppBar과 같이 다른보기의 구성 요소와 상호 작용할 때 문제가 발생합니다.

어쩌면 나는 부모보기를 비교하는 문제를 해결할 수 있고 동일한보기에서 나오는 경우 Focus (FocusState.Programmatic)를 실행할 수 있습니다.

하지만 ... 어떻게?

답변

0

설명에 따라 TextBox에 집중하고 싶습니다. 나는 간단한 데모를하고 이것을 참조 할 수 있습니다.

XAML : 뒤에

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Bottom"> 
    <TextBox x:Name="textbox1" Width="300" Height="50" HorizontalAlignment="Left" VerticalAlignment="Bottom"></TextBox> 
    </StackPanel> 
    <CommandBar> 
     <AppBarToggleButton Icon="Shuffle" Label="Shuffle" Click="AppBarButton_Click" /> 
     <AppBarToggleButton Icon="RepeatAll" Label="Repeat" Click="AppBarButton_Click"/> 
     <AppBarSeparator/> 
     <AppBarButton Icon="Back" Label="Back" Click="AppBarButton_Click"/> 
     <AppBarButton Icon="Stop" Label="Stop" Click="AppBarButton_Click"/> 
     <AppBarButton Icon="Play" Label="Play" Click="AppBarButton_Click"/> 
     <AppBarButton Icon="Forward" Label="Forward" Click="AppBarButton_Click"/> 
     <CommandBar.SecondaryCommands> 
      <AppBarButton Icon="Like" Label="Like" Click="AppBarButton_Click"/> 
      <AppBarButton Icon="Dislike" Label="Dislike" Click="AppBarButton_Click"/> 
     </CommandBar.SecondaryCommands> 
     <CommandBar.Content> 
      <TextBlock Text="Now playing..." Margin="12,14"/> 
     </CommandBar.Content> 
    </CommandBar> 
</Grid> 

코드 :

 public MainPage() 
    { 
     this.InitializeComponent(); 
     this.LayoutUpdated += MainPage_LayoutUpdated; 
    } 

    private void MainPage_LayoutUpdated(object sender, object e) 
    { 
     textbox1.Focus(Windows.UI.Xaml.FocusState.Programmatic); 
    } 

나는 또한 당신이 참조 할 수 one threads을 찾을 수 있습니다.