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

How to change default behaviour

3 Answers 41 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Berthold
Top achievements
Rank 1
Berthold asked on 11 Oct 2010, 07:21 AM
Hi, 

the default behaviour of the panelBar is: 
- expand subitems when they're collapsed, 
- collapse them, when they're expanded

Now I do want to change it like this:
- collapse only, when another Subitem is selected, but not when the same item is selected

Try to explain it in a example:
item1
   sub 11
   sub 12
   sub 13
item 2
   sub 21
   sub 22
When I click on item 1, the subitems 11 ...13 should be visible (expanded), even when the are already expanded. 
(currently the state is toggled)

I hope I could it explain clear enough.

Thanks for your help
Berthold



  
  

3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 14 Oct 2010, 01:23 PM
Hello Berthold,

A possible  way to implement such functionality is to handle the PreviewCollapsed event of the RadPanelBar when the item that is about to be collapsed is currently selected.

Please find the attached solution and let me know if it helps you. Feel free to ask if you need further help.

Kind regards,
Petar Mladenov
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
Berthold
Top achievements
Rank 1
answered on 19 Oct 2010, 07:48 AM
Hi,
I had to change the comparsion from

e.Handled = e.OriginalSource == (sender as RadPanelBar).SelectedItem;

to

 

e.Handled = e.OriginalSource.ToString() == (sender as RadPanelBar).SelectedItem.ToString();

 

 

 

 

than it works great - thanks for your hint. 


Another question: 
I set the Panel Source  in code behind, after clicking on the main-menu
panelBar.ItemsSource = myList (depending on menu item)

Now I want to expand and select the first item of the itemsource
I tried: panelBar.ChildrenOfType<RadPanelBarItem>()  but there are no items.

Regards
Berthold

 

 

 

 

 

 

0
Petar Mladenov
Telerik team
answered on 20 Oct 2010, 11:45 AM
Hi Berthold,

First of all, the solution I gave you last time works fine if the PanelBar is populated with data declaratively.
In case it is databound to a collection of data items, it is more appropriate to use the SelectedContainer property of the RadPanelBar:

private void radPanelBar_PreviewCollapsed(object sender, Telerik.Windows.RadRoutedEventArgs e)
       {
           e.Handled = e.OriginalSource == (sender as RadPanelBar).SelectedContainer;
       }

Using a comparison of strings requires perfectly overriden ToString() method of the DataItems - if two items are different , their ToString() methods should return different values. If this requirement is not fulfilled invoking of PreviewCollapsed may never stop and then StackOverflow exception occurs.

Using the method ChildrenOfType<RadPanelBarItem>()  requires all the containers of the PaneBar to be generated. This means you may had called this method before the generation of the containers was finished. However, a better practice in implementing your scenario is to add a property Expanded to your DataItem class and bind it to RadPanelBarItem`s property IsExpanded.

I prepared a sample project for you demonstrating how to bind IsExpanded using ContainerBindings.
Please take a look at it and let me know if it satisfies you.

Feel free to ask if you need further help.


All the best,
Petar Mladenov
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
Tags
PanelBar
Asked by
Berthold
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Berthold
Top achievements
Rank 1
Share this question
or