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

DataBinding SelectedItem property

4 Answers 127 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Matthew Cartwright
Top achievements
Rank 1
Matthew Cartwright asked on 25 Mar 2009, 04:26 PM
I'd like to use the panel bar and have the SelectedItem property bound to a property in my data context (I'm using an MVVM pattern and the ViewModel will be the data context for the view). 

The XAML is:
<nav:RadPanelBar Name="pbReportingMenu" SelectedItem="{Binding SelectedItem, Mode=TwoWay}"  > 

The code behind specifies the datacontext:
this.DataContext = new Menu_ViewModel(); 

And the Menu_ViewModel() class takes care of the property:
        private RadPanelBar _selectedItem; 
 
        public RadPanelBar SelectedItem 
        { 
            get { return _selectedItem; } 
            set 
            { 
                _selectedItem = value; 
                _OnPropertyChanged("SelectedItem"); 
            } 
        } 

When I add a breakpoint to my setter, it never gets hit. Any ideas?

(I have also tried using a dependency property, but this didn't work either)
        public RadPanelBar SelectedItem 
        { 
            get { return (RadPanelBar)GetValue(SelectedItemProperty); } 
            set { SetValue(SelectedItemProperty, value); } 
        } 
 
        // Using a DependencyProperty as the backing store for SelectedItem.  This enables animation, styling, binding, etc... 
        public static readonly DependencyProperty SelectedItemProperty = 
            DependencyProperty.Register("SelectedItem"typeof(RadPanelBar), typeof(Menu_ViewModel), new PropertyMetadata(null)); 
 
 

What types will the property be? 
Does TwoWay binding work on the SelectedItem property?

Thanks,

4 Answers, 1 is accepted

Sort by
0
Tihomir Petkov
Telerik team
answered on 26 Mar 2009, 08:24 AM
Hi Matthew,

I already replied to your support ticket on the same topic.

Regards,
Tihomir Petkov
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Scott
Top achievements
Rank 1
answered on 26 Jul 2010, 12:24 AM
Hi Tihomir,

I'm having a similar issue at the moment. I'm binding my View's RadPanelBar.SelectedItem using two-way binding in XAML to a public property on my ViewModel named SelectedUserItem. The VM property is public of type UserItem (a POCO object) and raises an INotifyPropertyChanged event in its setter.

When I set the SelectedUserItem in the ViewModel, the RadPanelBar does not "select" the associated UserItem; however, when I click on a RadPanelBarItem in the View, the SelectedUserItem is set as expected.

Can the RadPanelBar.SelectedItem property be set through xaml binding?

Cheers,
Scott
0
Hristo
Telerik team
answered on 27 Jul 2010, 07:06 AM
Hello Scott,

This is a bug in the component. We will fix it shortly with the next release. I can provide you with workaround till then. You can attach binding to SelectedItem property of the RadPanelBarItem instead to SelectedItem of the RadPanelbar. You can extend your viewmodel to support IsSelected property and fire the PropertyChanged event when changing the viewmodel. I'm attaching a working example demonstrating how to do it. The commented lines were used to simulate your case.

Best wishes,
Hristo Milyakov
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
0
Scott
Top achievements
Rank 1
answered on 27 Jul 2010, 11:27 PM
Hi Hristo,

Thanks very much for providing the workaround sample project. Good to know it will be fixed in the next release.

Cheers,
Scott
Tags
PanelBar
Asked by
Matthew Cartwright
Top achievements
Rank 1
Answers by
Tihomir Petkov
Telerik team
Scott
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or