Thanks for reaching out.
A WPF TextBox placed over the active Excel cell shows correctly, but typing goes to Excel. The TextBox never receives TextChanged or KeyDown.
you can use in a VSTO add‑in to make a WPF TextBox overlay over the active Excel cell receive KeyDown/TextChanged reliably. It addresses Excel’s focus‑stealing during selection changes and in‑cell edit mode.
1) WPF overlay window (top‑level, focusable)
please check below code
CellOverlayWindow.xaml.txt
2) VSTO wiring (subscribe, position, focus, commit/cancel)
please check below code
note 2 code.txt
3. What this solves (and why it works)
- Excel steals focus on selection changes and when entering in‑cell edit.
- The overlay is a top‑level, focusable WPF window. We defer Activate() + Focus() using Dispatcher.BeginInvoke (ApplicationIdle) so it executes after Excel’s own activation finishes.
- We temporarily disable Application.EditDirectlyInCell while the overlay is shown, so Excel doesn’t switch to in‑cell edit and monopolize the input pipeline.
- Optional Win32 focus (SetForegroundWindow + SetFocus) is available for stubborn environments.
- Enter/Esc commit/cancel, then we restore focus to Excel and revert EditDirectlyInCell.
4) Usage notes
- If you support IME/East Asian input, also wire PreviewTextInput and PreviewKeyDown on the TextBox.
- Avoid AllowsTransparency=True/hit‑test transparent windows; they won’t own keyboard focus.
- If your layout includes borders/margins, adjust overlay.Width/Height accordingly.
Let us know if the issue persists after following these steps. I’ll be happy to assist further if needed.
If the issue has been resolved, Kindly mark the provided solution as "Accept Answer", so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.