SetFocus on databoun TabControl

4 posts, 0 answers
  1. Francisco Martinez
    Francisco Martinez avatar
    3 posts
    Member since:
    Nov 2009

    Posted 20 Jan 2011 Link to this post

    Hi there,

    I'm developing an app using WPF and MVVM, as well as the latest version of RadControls for WPF. I have a RadTabControl that contains my views, bound to an IEnumerable, and everything is working perfectly. However, when I add a new view to the IEnumerable, I'd like to give it focus.

    Is there anyway I can achieve this functionality? I can only access the views via the Items property, but not the TabItem associated.

    Thanks in advance!
  2. Francisco Martinez
    Francisco Martinez avatar
    3 posts
    Member since:
    Nov 2009

    Posted 21 Jan 2011 Link to this post

    Hello again,

    I have some news. After digging around, I finally got the RadTabItem for the currently selected item.

    RadTabItem tabItem =  container.ItemContainerGenerator.ContainerFromIndex(container.SelectedIndex) as RadTabItem;
    if (tabItem != null)
    {
        tabItem.Focus();
    }

    But even with this, it's not getting focused "visually". If you check the IsFocused property, it is set as true as it should be, but nothing happens. Before databinding the ItemsSource of the RadTabControl, I was creating new RadTabItems and adding them to the RadTabControl.Items property, and giving them focus worked :(

    Any ideas? Thanks again!
  3. UI for WPF is Visual Studio 2017 Ready
  4. Francisco Martinez
    Francisco Martinez avatar
    3 posts
    Member since:
    Nov 2009

    Posted 21 Jan 2011 Link to this post

    Ok, it's finally done. There's nothing as asking a question to find the answer by yourself ;) In case anyone is interested, the SelectedIndex property wasn't changing, so all I needed to do was

    container.SelectedItem = item;
    RadTabItem tabItem = container.ItemContainerGenerator.ContainerFromIndex(container.SelectedIndex) as RadTabItem;  
      
    if (tabItem != null)
    {
        tabItem.Focus();
    }

    where item is my data item. Now it's working perfectly.

    Thanks!
  5. Suresh
    Suresh avatar
    14 posts
    Member since:
    Jun 2011

    Posted 03 Aug 2011 Link to this post

    I have used the code below and it worked just fine.

    SelectedIndex="{Binding Path=SelectedIndex, Mode=TwoWay}"

    Setting the SelectedIndex highlights the corresponding tab.
Back to Top