DataBinding SelectedItem property

5 posts, 0 answers
  1. Matthew Cartwright
    Matthew Cartwright avatar
    31 posts
    Member since:
    Oct 2005

    Posted 25 Mar 2009 Link to this post

    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,
  2. Tihomir Petkov
    Admin
    Tihomir Petkov avatar
    576 posts

    Posted 26 Mar 2009 Link to this post

    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.
  3. DevCraft banner
  4. Scott
    Scott avatar
    42 posts
    Member since:
    Feb 2009

    Posted 25 Jul 2010 Link to this post

    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
  5. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 27 Jul 2010 Link to this post

    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
  6. Scott
    Scott avatar
    42 posts
    Member since:
    Feb 2009

    Posted 27 Jul 2010 Link to this post

    Hi Hristo,

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

    Cheers,
    Scott
Back to Top
DevCraft banner