2011-10-17 146 views
0

我有一個文本塊,擴展器和一個文本框...焦點光標在WPF中閃爍

這些位於列表視圖列的標題內。

TextBlock用於列表視圖列名稱,點擊擴展器...將顯示文本框...並且用戶可以基於該列來列出列表視圖。該文本框默認處於摺疊狀態。

我的要求是,當用戶點擊擴展器時,文本框應該顯示給用戶...並且焦點應該在文本框上。

通過以下XAML,我能夠顯示在擴展的點擊文本框,並設置文本框我的焦點(光標)。 但該光標不閃爍。我的意思是我必須在文本框中再次點擊輸入的東西

請幫我找出是什麼問題...任何幫助,將不勝感激。

<StackPanel> 
    <DockPanel> 
     <TextBlock DockPanel.Dock="Left" Text="ID"/> 
     <Expander x:Name="IdExp" DockPanel.Dock="Right" IsExpanded="False" ExpandDirection="Down" >               
                     </Expander>                 
    </DockPanel> 

    <TextBox x:Name="PropertyCCCIDSearch" 
     Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}, 
                 Path=DataContext.SearchCCGId.Value,UpdateSourceTrigger=PropertyChanged}" 
    Visibility="{Binding ElementName=IdExp, Path=IsExpanded, Converter={x:Static local:Converters.BoolToVisibility}}" >     
    <TextBox.Style> 

    <Style> 
    <Style.Triggers>                    <DataTrigger Binding="{Binding ElementName=IdExp, Path=IsExpanded}" Value="True"> 
     <Setter Property="FocusManager.FocusedElement" Value="{Binding  ElementName=PropertyCCCIDSearch}"/>              </DataTrigger> 
    </Style.Triggers> 
    </Style> 
    </TextBox.Style> 
</TextBox>                
</StackPanel> 
+0

給定的代碼是爲我工作的罰款.... – Shebin

回答

0

您的代碼是否正常工作,這是我的嘗試

<Window.Resources> 
     <BooleanToVisibilityConverter x:Uid="BooleanToVisibilityConverter_1" x:Key="b2v" /> 
    </Window.Resources> 
    <Grid> 
     <StackPanel> 
      <DockPanel> 
       <TextBlock DockPanel.Dock="Left" Text="ID"/> 
       <Expander x:Name="IdExp" DockPanel.Dock="Right" IsExpanded="False" ExpandDirection="Down" > 
       </Expander> 
      </DockPanel> 
      <TextBox x:Name="PropertyCCCIDSearch" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}, 
                 Path=DataContext.SearchCCGId.Value,UpdateSourceTrigger=PropertyChanged}" 
        Visibility="{Binding ElementName=IdExp, Path=IsExpanded, 
        Converter={StaticResource b2v}}" > 
       <TextBox.Style> 
        <Style> 
         <Style.Triggers> 
          <DataTrigger Binding="{Binding ElementName=IdExp, Path=IsExpanded}" Value="True"> 
           <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=PropertyCCCIDSearch}"/> 
          </DataTrigger> 
         </Style.Triggers> 
        </Style> 
       </TextBox.Style> 
      </TextBox> 
     </StackPanel> 

    </Grid> 
</Window> 
+0

你做什麼樣的改變不是讓轉換器資源等? – Relativity

+0

它對我來說工作得很好......不知道你的機器中發生了什麼 – Shebin