WPF 中焦点光标闪烁

发布于 2024-12-10 02:48:28 字数 1810 浏览 0 评论 0原文

我有一个文本块、扩展器和一个文本框...

这些位于列表视图列的标题内。

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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如此安好 2024-12-17 02:48:28

您的代码工作正常,这就是我尝试过的

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文