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

Selected Category and Item binding

1 Answer 25 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 15 Jul 2011, 03:19 PM
I'm using the RadPanelBar to present a number of Categories, each with a set of Items within them.  The user can then expand a category and select an item within it.

The SelectedItem is bound to the ViewModel, but this is set regardless of whether a Header (Category) is selected or an item under the header.  This means that the target in the ViewModel either raises binding exceptions or has to be weakly-typed (e.g. of type Object).

I have other controls on-screen that need to react to the changes in the selected item, is there a way to separate out "HeaderSelected" and "ItemSelected" events?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 20 Jul 2011, 03:36 PM
Hi Daniel,

The only way to achieve this functionality is to control it from the ViewModel. What I mean is the following.
Imagine you have an object SelectedItem property in the ViewModel. You will have to notify the rest of the controls that the SelectedItem has changed only if it of type Category. Something like this:

public class ViewModel : INotifyPropertyChanged
{
    private object selectedItem;
 
    public object SelectedItem
    {
        get
        {
            return this.selectedItem;
        }
        set
        {
            if (this.selectedItem != value)
            {
                this.selectedItem = value;
 
                // Notify that the SelectedItem has changed only if it of type Category
                if (this.selectedItem is Category)
                {
                    this.OnPropertyChanged("SelectedItem");
                }
            }
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;
 
    private void OnPropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

This means that you're correct when saying that the SelectedItem has to be of type object and not Category.

In my opinion this is the most viable option in this particular scenario. Let me know what you thing about it. I'd be glad to further continue the discussion with you.

Kind regards,
Kiril Stanoev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
PanelBar
Asked by
Daniel
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Share this question
or