2009-07-31 2 views
2

에서 텍스트 상자에 포커스를 설정하고(); selectionChanged의 이벤트 처리기에서 작동하지만 작동하지 않습니다.을 TabControl은, 내가 textBox_n.Focus의 코드를 추가</p> <p>특정 텍스트 상자에 포커스를 설정하려면 내가 특정 TabItem의로 전환하면 내가 WPF 에있는 TabControl이 WPF

tabItem의 GotFocus 이벤트 핸들러에 코드를 추가했지만 재미있는 textBox_n.Focus() 호출은 tabItem의 GotFocus를 다시 호출했습니다.

그래서 어디서 무엇을 놓을까요?

답변

0

격자를 사용하여 텍스트 상자를 정렬하는 경우 초점을 맞추려는 격자를 격자의 첫 번째 자식으로두고 행과 열을 두 번째 또는 세 번째로 지정할 수 있습니다.

<TabControl> 
     <TabItem Header="Tab 1"> 

     </TabItem> 
     <TabItem Header="Tab 2"> 
      <Grid> 
       <Grid.RowDefinitions> 
        <RowDefinition Height="Auto" /> 
        <RowDefinition Height="Auto" /> 
       </Grid.RowDefinitions> 
       <TextBox Grid.Row="1" Margin="5">textBox2</TextBox> <!-- This textbox is the first child of the grid, so it gets focused --> 
       <TextBox Grid.Row="0" Margin="5">textBox1</TextBox> <!-- This textbox is catually on top of textBox2 --> 
      </Grid> 
     </TabItem> 
    </TabControl> 

물론 우아하지는 않지만 빠르게 완료됩니다. 또한 코드 숨김도 필요하지 않습니다.