Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > TabControl > RadTabControl SelectedItem Binding Problem

Not answered RadTabControl SelectedItem Binding Problem

Feed from this thread
  • Posted on Jan 30, 2012 (permalink)

    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.



    Reply

  • Petar Mladenov Petar Mladenov admin's avatar

    Posted on Feb 2, 2012 (permalink)

    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 >>

    Attached files

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > TabControl > RadTabControl SelectedItem Binding Problem
Related resources for "RadTabControl SelectedItem Binding Problem"

WPF TabControl Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]