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

        <tfoot id='NXsPW'></tfoot>
      1. <small id='NXsPW'></small><noframes id='NXsPW'>

          <bdo id='NXsPW'></bdo><ul id='NXsPW'></ul>
      2. 不集中时如何保持WPF文本框选择?

        How to keep WPF TextBox selection when not focused?(不集中时如何保持WPF文本框选择?)

          <bdo id='yJiG0'></bdo><ul id='yJiG0'></ul>

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

                  <tbody id='yJiG0'></tbody>
                  <legend id='yJiG0'><style id='yJiG0'><dir id='yJiG0'><q id='yJiG0'></q></dir></style></legend><tfoot id='yJiG0'></tfoot>
                1. <small id='yJiG0'></small><noframes id='yJiG0'>

                2. 本文介绍了不集中时如何保持WPF文本框选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在 WPF 文本框中显示一个选择,即使它不在焦点上.我该怎么做?

                  I want to show a selection in a WPF TextBox even when it's not in focus. How can I do this?

                  推荐答案

                  我已经将此解决方案用于 RichTextBox,但我认为它也适用于标准文本框.基本上,您需要处理 LostFocus 事件并将其标记为已处理.

                  I have used this solution for a RichTextBox, but I assume it will also work for a standard text box. Basically, you need to handle the LostFocus event and mark it as handled.

                    protected void MyTextBox_LostFocus(object sender, RoutedEventArgs e)
                    {    
                       // When the RichTextBox loses focus the user can no longer see the selection.
                       // This is a hack to make the RichTextBox think it did not lose focus.
                       e.Handled = true;
                    }
                  

                  TextBox 不会意识到它失去了焦点,仍然会显示突出显示的选择.

                  The TextBox will not realize it lost the focus and will still show the highlighted selection.

                  在这种情况下我没有使用数据绑定,所以这可能会弄乱双向绑定.您可能必须在 LostFocus 事件处理程序中强制绑定.像这样的:

                  I'm not using data binding in this case, so it may be possible that this will mess up the two way binding. You may have to force binding in your LostFocus event handler. Something like this:

                       Binding binding = BindingOperations.GetBinding(this, TextProperty);
                       if (binding.UpdateSourceTrigger == UpdateSourceTrigger.Default ||
                           binding.UpdateSourceTrigger == UpdateSourceTrigger.LostFocus)
                       {
                          BindingOperations.GetBindingExpression(this, TextProperty).UpdateSource();
                       }
                  

                  这篇关于不集中时如何保持WPF文本框选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                      1. <legend id='25m0L'><style id='25m0L'><dir id='25m0L'><q id='25m0L'></q></dir></style></legend>
                        <tfoot id='25m0L'></tfoot>

                        <small id='25m0L'></small><noframes id='25m0L'>

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

                            <bdo id='25m0L'></bdo><ul id='25m0L'></ul>