Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Maybe it's not nice to answer own questions, but I think this answer is more suitable to the question than others, and therefore worth to be written. Surely this was also because I did not describe the problem clearly enough.</p> <p>Finally, just as a quick'n'dirty proof of concept, I worked around it like this: The LostFocus-Event is never fired on the TextBox, when I switch the tab. Therefore, the binding doesn't update and the entered value is lost, because switching back makes the binding refresh from its source. But what IS fired is the PreviewLostFocus-Event, hence I hooked in this tiny function, that manually triggers the update to the binding source:</p> <pre><code>private void BeforeFocusLost(object sender, KeyboardFocusChangedEventArgs e) { if (sender is TextBox) { var tb = (TextBox)sender; var bnd = BindingOperations.GetBindingExpression(tb, TextBox.TextProperty); if (bnd != null) { Console.WriteLine(String.Format("Preview Lost Focus: TextBox value {0} / Data value {1} NewFocus will be {2}", tb.Text, bnd.DataItem, e.NewFocus)); bnd.UpdateSource(); } Console.WriteLine(String.Format("Preview Lost Focus Update forced: TextBox value {0} / Data value {1} NewFocus will be {2}", tb.Text, bnd.DataItem, e.NewFocus)); } } </code></pre> <p>The output according to the event chain with PreviewLostFocus, LostFocus (both from TextBox) and SelectionChanged (from TabControl) will look like this:</p> <blockquote> <p>Preview Lost Focus: TextBox value Smith123456 / Data value John Smith123 NewFocus will be System.Windows.Controls.TabItem Header:Peter Miller Content:Peter Miller Preview Lost Focus Update forced: TextBox value Smith123456 / Data value John Smith123456 NewFocus will be System.Windows.Controls.TabItem Header:Peter Miller Content:Peter Miller Selection changed from System.Object[] to System.Object[] Preview Lost Focus: TextBox value Miller / Data value Peter Miller NewFocus will be System.Windows.Controls.TextBox: Peter Preview Lost Focus Update forced: TextBox value Miller / Data value Peter Miller NewFocus will be System.Windows.Controls.TextBox: Peter Lost Focus having value Miller</p> </blockquote> <p>We see that the LostFocus only occurs at the end, but not before changing the TabItem. Still I think this is strange, possibly a bug in WPF or in the standard control templates. Thank you all for your suggestions, sorry I couldn't really sign them to be answers, as they did not solve the loss of entries on tab-change.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload