Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
615
Setting focus to special editable control in tabitemex
posted

Hi

when selectionchanged in XamTabControl ,how can Setting focus to special editable control in active tabitemex?

 

thank you very much

  • 54937
    Verified Answer
    Offline posted

    Well in all likelihood the layout will not be updated by the time that event is invoked so the element won't really be in view. What you may be able to do is to force a layout update but it would probably be best though to just wait for the layout update to happen normally as the selection changed may fire while things are still being updated. e.g.

    private void XamTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
    if (e.AddedItems.Count > 0)
    {
    TabItem tab = e.AddedItems[0] as TabItem;
     
    if (tab.Name == "tabOther")
    {
    var callback = new DispatcherOperationCallback(FocusElement);
    this.Dispatcher.BeginInvoke(DispatcherPriority.Render, callback, this.btn2);
    }
    }
    }
     
    private static object FocusElement(object parameter)
    {
    IInputElement element = parameter as IInputElement;
     
    if (null != element)
    element.Focus();
    return null;
    }