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

RadTabControl SelectedItem Binding Problem

1 Answer 340 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Kevin Marois
Top achievements
Rank 1
Kevin Marois asked on 30 Jan 2012, 10:23 PM
I am populating a RadTabControl in the code-behind, and it's bound to a property called SelectedBottomTab.

Here's the XAML
<telerik:RadTabControl x:Name="tabBottomTabPanel"
                        Grid.Row="2"
                        ItemsSource="{Binding BottomTabs}" 
                        SelectedItem="{Binding SelectedBottomTab}">
</telerik:RadTabControl>

then in the code behin I create the tabs:

private ObservableCollection<RadTabItem> _BottomTabs;
public ObservableCollection<RadTabItem> BottomTabs
{
    get { return _BottomTabs; }
    set
    {
        if (_BottomTabs != value)
        {
            _BottomTabs = value;
            RaisePropertyChanged("BottomTabs");
        }
    }
}
  
private RadTabItem _SelectedBottomTab = null;
public RadTabItem SelectedBottomTab
{
    get { return _SelectedBottomTab; }
    set
    {
        if (_SelectedBottomTab != value)
        {
            _SelectedBottomTab = value;
            RaisePropertyChanged("SelectedBottomTab");
        }
  
    }
}

and
private void setupBottomTabs()
{
    RadTabItem tabA = new RadTabItem { Header = "Tab A" };
    RadTabItem tabB = new RadTabItem { Header = "Tab B" };
    RadTabItem tabC = new RadTabItem { Header = "Tab C" };
  
    BottomTabs = new ObservableCollection<RadTabItem>();
    BottomTabs.Add(tabA);
    BottomTabs.Add(tabB);
    BottomTabs.Add(tabC);
}

When change tabs the SelectedBottomTab property set it not firing.



1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 02 Feb 2012, 11:18 AM
Hello Kevin Marois ,

The setter does not fire because you haven't set TwoWay Binding in XAML:
SelectedItem="{Binding SelectedBottomTab, Mode=TwoWay}"

However, using a UiElements (RadTabItems) as a ViewModels is bad by design and may lead to various issues. Actually, when you bind the RadTabControl to collection of business objects, the RadTabItems are automatically created and you only define how they will look by ItemTemplate. I re-factored your solution accordingly. Please check it out and let us know if it satisfies you.

 However, 
Regards,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
TabControl
Asked by
Kevin Marois
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or