且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WPF:数据绑定选中新选项卡时,TabControl不提交更改

更新时间:2023-12-06 17:32:22

这个问题在这里很好地描述:WPF绑定:使用LostKeyboardFocus而不是LostFocus作为UpdateSourceTrigger 非常有趣看到从微软的家伙知道这个问题几年,但仍然没有固定。
也是一个很大的讨论:保存前的WPF数据绑定

This issue is well described here: WPF Binding: Use LostKeyboardFocus instead of LostFocus as UpdateSourceTrigger Very interesting to see that guys from Microsoft knows about this problem for several years but still not fixed it. Also a big discussing here: WPF Databind Before Saving

这个黑客工程:

    <TabControl SelectionChanged="OnSelectionChanged">

和codebehind:

And codebehind:

    private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (Keyboard.FocusedElement is TextBox)
            Keyboard.FocusedElement.RaiseEvent(new RoutedEventArgs(LostFocusEvent));
    }