2011-10-15 46 views
1

我有一個擴展器...和一個文本框。該文本框默認是隱藏的。當用戶點擊擴展器時,我正在顯示文本框。這工作正常。如何在用戶點擊擴展器時在文本框中設置焦點?

我需要的是,當用戶點擊擴展器時......我需要在文本框中設置焦點。

請幫我做這個...我試着用下面的代碼...但似乎「IsFocused」是隻讀屬性。

任何幫助,將不勝感激!

<StackPanel> 
    <DockPanel> 
    <TextBlock DockPanel.Dock="Left" Text="ID"/> 
     <Expander x:Name="ID" DockPanel.Dock="Right" IsExpanded="False" ExpandDirection="Down">              
     </Expander> 
    </DockPanel> 
    <TextBox Text="{Binding Path=SearchCCCId.Value,UpdateSourceTrigger=PropertyChanged}" 
    Visibility="{Binding ElementName=ID,Path=IsExpanded,Converter={x:Static local:Converters.BoolToVisibility}}" Width="70" > 
    <TextBox.Style> 
    <Style> 
     <Style.Triggers> 
      <DataTrigger Binding="{Binding ElementName=ID, Path=IsEpanded}" Value="True" > 
       <Setter Property="IsFocused" Value="True" /> 
      </DataTrigger> 
     </Style.Triggers> 
    </Style> 
    </TextBox.Style> 
    </TextBox> 
</StackPanel> 

回答

0

您可以處理Expanded事件的Expander並設置焦點內部處理程序的方法。

private void OnExpanderExpanded(object sender, RoutedEventArgs args) 
{ 
    txtTest.Focus(); 
} 
1

有了你們的幫助,我能找出答案......

<TextBox.Style> 
    <Style> 
     <Style.Triggers> 
      <DataTrigger Binding="{Binding ElementName=ID, Path=IsExpanded}" Value="True"> 
       <Setter Property="FocusManager.FocusedElement" 
         Value="{Binding ElementName=PropertyIDSearch}"/> 
      </DataTrigger> 
     </Style.Triggers> 
    </Style> 
</TextBox.Style> 
相關問題