Ok, i was able to replace half of the solution with wpf-acceptable code, i.e. for a separate stackpanel, which contained controls which i didn't want to steal focus from my textbox, i simply set that stackpanel to have this property: FocusManager.IsFocusScope="true", and what i understand this did was create a separate focus-tree/scope/thing so those controls would not be able to affect my textboxes focus. (source: http://wpfhacks.blogspot.com/2009/06/correct-way-keep-selection-in-textbox.html) But so far i do not see an alternative to the following code, which prevents the textbox from being notified that the window lost focus: #region WndProc in order to prevent the textbox from loosing focus when the window losses focus const int WM_KILLFOCUS = 8; protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); HwndSource source = PresentationSource.FromVisual(this) as HwndSource; source.AddHook(WndProc); } IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == WM_KILLFOCUS) handled = true; return IntPtr.Zero; } #endregion
modified on Tuesday, October 26, 2010 5:38 PM