Index: src/Common/DelftTools.Controls.Swf/ControlHelper.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/DelftTools.Controls.Swf/ControlHelper.cs (.../ControlHelper.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/DelftTools.Controls.Swf/ControlHelper.cs (.../ControlHelper.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -9,15 +9,11 @@ public static class ControlHelper { [DllImport("user32.dll")] - public extern static int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam); + public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam); [DllImport("uxtheme.dll", CharSet = CharSet.Unicode)] public static extern int SetWindowTheme(IntPtr hWnd, string textSubAppName, string textSubIdList); - // Import GetFocus() from user32.dll - [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Winapi)] - internal static extern IntPtr GetFocus(); - public static Control GetFocusControl() { Control focusControl = null; @@ -30,33 +26,43 @@ return focusControl; } - + /// /// Call this method on a view if you want to trigger data binding. For example when switching between views, closing a /// view or when performing a save. /// /// control to unfocus / trigger validation /// If 'true', it messes with switch to another control/tab, but it is required /// if you close a view or want the current view to commit any changes. - public static void UnfocusActiveControl(IContainerControl containerControl, bool notSwitchingToOtherControl=false) + public static void UnfocusActiveControl(IContainerControl containerControl, bool notSwitchingToOtherControl = false) { if (containerControl == null) + { return; + } while (containerControl.ActiveControl is IContainerControl) + { containerControl = containerControl.ActiveControl as IContainerControl; + } var control = containerControl as Control; if (notSwitchingToOtherControl && control != null && !control.ContainsFocus) + { control.Focus(); - + } + containerControl.ActiveControl = null; //unfocus current control, to force binding to happen } - + public static IEnumerable GetChildControls(Control control) { var controls = control.Controls.Cast(); return control.Controls.OfType().Concat(controls.SelectMany(GetChildControls)); } + + // Import GetFocus() from user32.dll + [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Winapi)] + internal static extern IntPtr GetFocus(); } } \ No newline at end of file