0
votes

I've just discovered recently the source of a problem that has been occurring within an application that I've been working on that uses traditional WinForms MDI with WPF UserControls hosted within ElementHosts for each form. The problem is that if the user changes the text in a TextBox that is TwoWay bound to a ViewModel property that the setter on the property is not set when clicking on the Save button in the toolbar. The consequence of this behavior is that the last text setting that was set is not being saved.

I'm using the default UpdateSourceTrigger value of LostFocus so I believe what is happening is that the the WPF TextBox element is not loosing focus when I click on the WinForms based Save button in the toolbar. So now that I understand the issue I'm curious what the correct or best way is to solve this problem.

The two main options that I can think of either require manual prompting to update the setter without causing the control to loose focus or just make the TextBox loose focus so that the normal source updating occurs.

1
You may be able to hook into the leave or lost focus on the UserControl.paparazzo
I'll look into doing so however I believe those events do not fire either because as far as the WPF UI infrastructure is concerned I'm still focused on the TextBox.jpierson
I've dabbled in the much broken focus scope implementation in WPF and I'm not looking forward to looking into it because it's likely a lost cause but I'm wondering if there is something I can trigger off of when these buttons are clicked that will allow me to manually shift focus in a sensible way?jpierson

1 Answers

0
votes

You can change UpdateSourceTrigger to PropertyChanged, then the "Save" button will work nicely.

I think your reasoning is correct. WPF and Winforms have both seperate "Focusmanagers", so if you go from WPF TextBox to winforms button, then focus has nowhere to go.