This is a migrated thread and some comments may be shown as answers.

SetFocus on databoun TabControl

3 Answers 114 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Francisco Martinez
Top achievements
Rank 1
Francisco Martinez asked on 20 Jan 2011, 07:56 PM
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!

3 Answers, 1 is accepted

Sort by
0
Francisco Martinez
Top achievements
Rank 1
answered on 21 Jan 2011, 09:02 AM

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!
0
Francisco Martinez
Top achievements
Rank 1
answered on 21 Jan 2011, 09:17 AM
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!
0
Suresh
Top achievements
Rank 1
answered on 03 Aug 2011, 10:38 PM
I have used the code below and it worked just fine.

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

Setting the SelectedIndex highlights the corresponding tab.
Tags
TabControl
Asked by
Francisco Martinez
Top achievements
Rank 1
Answers by
Francisco Martinez
Top achievements
Rank 1
Suresh
Top achievements
Rank 1
Share this question
or