private bool TrySetFocusInControl(Control parentControl, string nameOfChildToFocus) { // Search parent pane context to determine whether we should give focus to this control. Control focusControl = parentControl; // if we haven't specified a control to give focus, by default give it focus. focusControl = XWindow.FindControl(parentControl, nameOfChildToFocus); if (focusControl != null) { focusControl.Focus(); } return(focusControl != null && focusControl.ContainsFocus); }
/// <summary> /// The focus will only be set in the default control if it implements IFocusablePanePortion. /// Note that it may BE our First or SecondPane, or it may be a child of one of those. /// </summary> private void SetFocusInDefaultControl() { if (String.IsNullOrEmpty(m_defaultFocusControl)) { return; } var defaultFocusControl = (XWindow.FindControl(FirstControl, m_defaultFocusControl) ?? XWindow.FindControl(SecondControl, m_defaultFocusControl)) as IFocusablePanePortion; Debug.Assert(defaultFocusControl != null, "Failed to find focusable subcontrol.", "This MultiPane was configured to focus {0} as a default control. But it either was not found or was not an IFocuablePanePortion", m_defaultFocusControl); if (defaultFocusControl != null) { defaultFocusControl.IsFocusedPane = true; // Lets it know it can do any special behavior (e.g., DataPane) when it is the focused child. defaultFocusControl.Focus(); } }
/// <summary> /// The focus will only be set in the default control if it implements IFocusablePanePortion. /// Note that it may BE our First or SecondPane, or it may be a child of one of those. /// </summary> private void SetFocusInDefaultControl() { if (String.IsNullOrEmpty(m_defaultFocusControl)) { return; } var defaultFocusControl = (XWindow.FindControl(FirstControl, m_defaultFocusControl) ?? XWindow.FindControl(SecondControl, m_defaultFocusControl)) as IFocusablePanePortion; Debug.Assert(defaultFocusControl != null, "Failed to find focusable subcontrol.", "This MultiPane was configured to focus {0} as a default control. But it either was not found or was not an IFocuablePanePortion", m_defaultFocusControl); // LT-14222...can't do BeginInvoke until our handle is created...we attempt this multiple times since it is hard // to find the right time to do it. If we can't do it yet hope we can do it later. if (defaultFocusControl != null && this.IsHandleCreated) { defaultFocusControl.IsFocusedPane = true; // Lets it know it can do any special behavior (e.g., DataPane) when it is the focused child. BeginInvoke((MethodInvoker)(() => defaultFocusControl.Focus())); } }
/// <summary> /// return the control specified by the given (unique) id. /// </summary> /// <param name="idControl"></param> /// <returns>null, if it couldn't find the control.</returns> public Control FindControl(string idControl) { return(XWindow.FindControl(this, idControl)); }