RadTabControl SelectedItem Binding Problem

2 posts, 0 answers
  1. Kevin Marois
    Kevin Marois avatar
    16 posts
    Member since:
    May 2010

    Posted 30 Jan 2012 Link to this post

    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.



  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 02 Feb 2012 Link to this post

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

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top