0
votes

I have an textblock, expander and a textbox...

these are inside the header of a listview column.

TextBlock is for listview column name, on click of expander...textbox will be displayed...and user can seartch the listview based on that column. The textbox is collapsed by default.

My requirement is, when user click on the expander, textbox should be displayed to the user...and focus should be on the textbox.

With the below XAML, I am able to display the textbox on click of expander and set the focus(cursor) on my textbox. But that cursor is no blinking. I mean I have to again click on textbox to type something

Please help me to find out what the issue is...Any help would be appreciated.

    <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>
1
The given code is working fine for me.... - Shebin

1 Answers

0
votes

Your code is working correctly this is what i tried

<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>