Bind to TabItem IsSelected problems

2 posts, 1 answers
  1. Adiel
    Adiel avatar
    60 posts
    Member since:
    Jun 2012

    Posted 25 Apr 2010 Link to this post

    Hi
    I have couple of tabs with ViewModel class for each.
    I want to bind the IsSelected DP to a property in the VM.
    Somehow the property not updated in the view model.

    I've create a demo project very simple and straightforward.

    The  xaml:

     <Grid x:Name="LayoutRoot" 
              Background="White">  
            <Controls:RadTabControl> 
                <Controls:RadTabItem x:Name="tab1" 
                                     Header="tab1" 
                                     IsSelected="{Binding Tab1 }">  
                </Controls:RadTabItem> 
                <Controls:RadTabItem Header="tab2" 
                                     x:Name="tab2" 
                                     IsSelected="{Binding Tab2}" /> 
            </Controls:RadTabControl> 
            <StackPanel HorizontalAlignment="Right" 
                        Margin="0,0,40,0">  
                <TextBlock Text="{Binding AA}" /> 
                <Button x:Name="Select" 
                        Content="Select Tab 1" 
                        Click="Select_Click" /> 
                <Button x:Name="Select1" 
                        Content="Select Tab 2" 
                        Click="Select1_Click" /> 
            </StackPanel> 
        </Grid> 

    The code behinde:
     public partial class MainPage : UserControl  
        {  
            public MainPage()  
            {  
                InitializeComponent();  
                ViewModel = new vm();  
            }  
     
            public vm ViewModel  
            {  
                get { return DataContext as vm; }  
                set { DataContext = value; }  
            }  
            private void Select_Click(object sender, RoutedEventArgs e)  
            {  
                ViewModel.Tab1 = true;  
            }  
     
            private void Select1_Click(object sender, RoutedEventArgs e)  
            {  
                ViewModel.Tab2 = true;  
            }  
        } 

    The view model:
     public class vm : INotifyPropertyChanged  
        {  
            private bool _tab1;  
            private bool _tab2;  
            public string AA  
            {  
                get 
                {  
                    return Tab1 ? "Tab1" : "Tab2";  
                }  
                set { OnPropChanged("AA"); }  
            }  
            public bool Tab1  
            {  
                get { return _tab1; }  
                set 
                {  
                    _tab1 = value;  
                    OnPropChanged("Tab1");  
                    OnPropChanged("AA");  
                }  
            }  
            public bool Tab2  
            {  
                get { return _tab2; }  
                set 
                {  
                    _tab2 = value;  
                    OnPropChanged("Tab2");  
                    OnPropChanged("AA");  
                }  
            }  
            private void OnPropChanged(string propName)  
            {  
                if (PropertyChanged != null)  
                    PropertyChanged(thisnew PropertyChangedEventArgs(propName));  
            }
            #region INotifyPropertyChanged Members  
     
            public event PropertyChangedEventHandler PropertyChanged;
            #endregion  
        } 

    Any ideas?
    Thanks
  2. Answer
    Vladislav
    Admin
    Vladislav avatar
    276 posts

    Posted 28 Apr 2010 Link to this post

    Hello Adiel,

    Can you please review the attached project?
    Basically I just added "Mode=TwoWay" in the binding expressions for "IsSelected" properties of the RadTabItems.

    Please, let us know if this solution works for you. 

    Kind regards,
    Vladislav
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
Back to Top