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

Delegate on TabControl

4 Answers 101 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 15 Aug 2009, 03:57 AM
Is there a way to use a Delegate on the TabControl?

Currently, I have (in XAML):
  SelectionChanged="radTabControl1_SelectionChanged"

in the ViewModel:
        public ICommand TabSelectionChangedCommand { get; private set; } 
 
            TabSelectionChangedCommand = new DelegateCommand<object>(param => 
            { 
                SelectionChanged(param); 
            }); 
 
        private void SelectionChanged(object obj) 
        { stuff } 

     And my otherwise empty .xaml.cs file:

        private void radTabControl1_SelectionChanged(object sender, System.Windows.RoutedEventArgs e) 
        { 
            FrameworkElement fe = (FrameworkElement)sender; 
            MyViewModel mvm = (MyViewModel) ((ObjectDataProvider)fe.DataContext).ObjectInstance; 
            if (mvm != null) 
            { 
                mvm.TabSelectionChangedCommand.Execute(sender); 
            } 
        } 
    
 
 
It works, but aren't we supposed to be able to do things without the code-behind?

Or, is there a better way to bind to the SelectedIndex ?

4 Answers, 1 is accepted

Sort by
0
Tihomir Petkov
Telerik team
answered on 18 Aug 2009, 05:58 PM
Hello Adam,

What about two-way data binding the SelectedIndex property to a public property in your ViewModel? If the ViewModel implements the INotifyPropertyChanged interface and you add a getter and setter to the property, I believe you will be able to catch the change of the selected tab in the RadTabControl. Please try the suggested approach and let me know if it works for you.

Regards,
Tihomir Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Adam
Top achievements
Rank 1
answered on 19 Aug 2009, 02:09 AM
No, it does not.

I tried both
SelectedItem="{Binding CurrentState, Mode=TwoWay}"
and
SelectedItem="{Binding Path=CurrentState, Mode=TwoWay}"

0
Accepted
Miroslav
Telerik team
answered on 19 Aug 2009, 08:01 AM
Hi Adam,

I created a small example with binding the SelectedItem property. It works as expected, so possibly I am missing something in your scenario.

The CurrentState property which you bind to needs to be of the type of the item in the TabControl (RadTabItem or some ViewModel class if you are binding the TabControl). You can see if the binding is working by making the CurrentState property an object. Also, you may want to check the output window in Visual Studio which will output a message for the bindings that break.

Hopefully this will help you,

Greetings,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Adam
Top achievements
Rank 1
answered on 19 Aug 2009, 05:35 PM
Life is easier when you bind to an object instead of an int,,,

Thanks!
Tags
TabControl
Asked by
Adam
Top achievements
Rank 1
Answers by
Tihomir Petkov
Telerik team
Adam
Top achievements
Rank 1
Miroslav
Telerik team
Share this question
or