• <small id='5Am7t'></small><noframes id='5Am7t'>

      <tfoot id='5Am7t'></tfoot>
      <i id='5Am7t'><tr id='5Am7t'><dt id='5Am7t'><q id='5Am7t'><span id='5Am7t'><b id='5Am7t'><form id='5Am7t'><ins id='5Am7t'></ins><ul id='5Am7t'></ul><sub id='5Am7t'></sub></form><legend id='5Am7t'></legend><bdo id='5Am7t'><pre id='5Am7t'><center id='5Am7t'></center></pre></bdo></b><th id='5Am7t'></th></span></q></dt></tr></i><div id='5Am7t'><tfoot id='5Am7t'></tfoot><dl id='5Am7t'><fieldset id='5Am7t'></fieldset></dl></div>
        <bdo id='5Am7t'></bdo><ul id='5Am7t'></ul>
    1. <legend id='5Am7t'><style id='5Am7t'><dir id='5Am7t'><q id='5Am7t'></q></dir></style></legend>

        WPF:当 TextBox 具有焦点时为 ListBox 设置 IsSelected,而不会丢失 LostFocus 上

        WPF: Setting IsSelected for ListBox when TextBox has focus, without losing selection on LostFocus(WPF:当 TextBox 具有焦点时为 ListBox 设置 IsSelected,而不会丢失 LostFocus 上的选择)
      1. <legend id='rAUzJ'><style id='rAUzJ'><dir id='rAUzJ'><q id='rAUzJ'></q></dir></style></legend>

        <small id='rAUzJ'></small><noframes id='rAUzJ'>

      2. <tfoot id='rAUzJ'></tfoot>

          <i id='rAUzJ'><tr id='rAUzJ'><dt id='rAUzJ'><q id='rAUzJ'><span id='rAUzJ'><b id='rAUzJ'><form id='rAUzJ'><ins id='rAUzJ'></ins><ul id='rAUzJ'></ul><sub id='rAUzJ'></sub></form><legend id='rAUzJ'></legend><bdo id='rAUzJ'><pre id='rAUzJ'><center id='rAUzJ'></center></pre></bdo></b><th id='rAUzJ'></th></span></q></dt></tr></i><div id='rAUzJ'><tfoot id='rAUzJ'></tfoot><dl id='rAUzJ'><fieldset id='rAUzJ'></fieldset></dl></div>

            • <bdo id='rAUzJ'></bdo><ul id='rAUzJ'></ul>
                  <tbody id='rAUzJ'></tbody>
                1. 本文介绍了WPF:当 TextBox 具有焦点时为 ListBox 设置 IsSelected,而不会丢失 LostFocus 上的选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个带有 ListBoxItems 和模板的 ListBox,因此它们包含 TextBoxes

                  I've a ListBox with ListBoxItems with a template so they contain TextBoxes

                  TextBox 获得焦点时,我希望选择 ListBoxItem.我发现的一种解决方案如下所示:

                  When the TextBox gets focused I want the ListBoxItem to be selected. One solution I've found looks like this:

                  <Style TargetType="{x:Type ListBoxItem}">
                      <Style.Triggers>
                          <Trigger Property="IsKeyboardFocusWithin" Value="True">
                              <Setter Property="IsSelected" Value="True"></Setter>
                          </Trigger>
                      </Style.Triggers>
                  </Style>
                  

                  这很好用,但是当 TextBox 失去焦点时,选择也会失去焦点.

                  This works great, but when the TextBox loses focus so does the selection.

                  有没有办法防止这种情况发生?

                  Is there a way to prevent this from happening?

                  推荐答案

                  我发现的最好的解决方案是:

                  Best solution I've found to do this with no code behinde is this:

                  <Style TargetType="{x:Type ListBoxItem}">
                      <Style.Triggers>
                          <EventTrigger RoutedEvent="PreviewGotKeyboardFocus">
                              <BeginStoryboard>
                                  <Storyboard>
                                      <BooleanAnimationUsingKeyFrames
                                          Storyboard.TargetProperty="(ListBoxItem.IsSelected)">
                  
                                          <DiscreteBooleanKeyFrame KeyTime="0" Value="True"/>
                                      </BooleanAnimationUsingKeyFrames>
                                  </Storyboard>
                              </BeginStoryboard>
                          </EventTrigger>
                      </Style.Triggers>
                  </Style>
                  

                  这篇关于WPF:当 TextBox 具有焦点时为 ListBox 设置 IsSelected,而不会丢失 LostFocus 上的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to keep the Text of a Read only TextBox after PostBack()?(PostBack()之后如何保留只读文本框的文本?)
                  Winforms Textbox - Using Ctrl-Backspace to Delete Whole Word(Winforms 文本框 - 使用 Ctrl-Backspace 删除整个单词)
                  C# - Add button click events using code(C# - 使用代码添加按钮单击事件)
                  Multi-color TextBox C#(多色文本框 C#)
                  How can i set the caret position to a specific index in passwordbox in WPF(如何将插入符号位置设置为 WPF 密码框中的特定索引)
                  C# Numeric Only TextBox Control(C# 纯数字文本框控件)
                    <bdo id='J4Rr4'></bdo><ul id='J4Rr4'></ul>

                      1. <legend id='J4Rr4'><style id='J4Rr4'><dir id='J4Rr4'><q id='J4Rr4'></q></dir></style></legend>

                      2. <small id='J4Rr4'></small><noframes id='J4Rr4'>

                        <tfoot id='J4Rr4'></tfoot>
                            <tbody id='J4Rr4'></tbody>

                            <i id='J4Rr4'><tr id='J4Rr4'><dt id='J4Rr4'><q id='J4Rr4'><span id='J4Rr4'><b id='J4Rr4'><form id='J4Rr4'><ins id='J4Rr4'></ins><ul id='J4Rr4'></ul><sub id='J4Rr4'></sub></form><legend id='J4Rr4'></legend><bdo id='J4Rr4'><pre id='J4Rr4'><center id='J4Rr4'></center></pre></bdo></b><th id='J4Rr4'></th></span></q></dt></tr></i><div id='J4Rr4'><tfoot id='J4Rr4'></tfoot><dl id='J4Rr4'><fieldset id='J4Rr4'></fieldset></dl></div>