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

Expand empty PanelBarItem

4 Answers 73 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Simon Stahl
Top achievements
Rank 1
Simon Stahl asked on 18 Jul 2009, 12:52 PM
Hi

I bound a RadPanelBar to a object structure like this:
- MyObject1.1 
    - MyObject2.1 
    - MyObject2.2 
- MyObject1.2 
- MyObject1.3 
    - MyObject2.3 
    - MyObject2.4 

it seems now, that empty PanelBarItems does not expand out of the box. so if I click on the header of the item "MyObject1.2" it does not expand nor the currently expanded one does collapse. I already figured out that i can catch the event "Selected" of the RadPanelBar to expand the item by myself:
private void RadPanelBar_Selected(object sender, RadRoutedEventArgs e) { 
    RadPanelBarItem selItem = e.OriginalSource as RadPanelBarItem; 
 
    if (selItem.Items.Count == 0) 
        selItem.IsExpanded = true

this works quite well, except that I am not able to collapse the last selected item. So my questions are:
- is there a better way to expand empty items?
- how can i collapse the items manually?

thanks
Simon

4 Answers, 1 is accepted

Sort by
0
Tihomir Petkov
Telerik team
answered on 20 Jul 2009, 07:25 AM
Hi Simon,

Why do you want to expand an item that has no content besides its header? Even if you expand it manually there will still be nothing to be displayed.

You are correct that by default a PanelBarItem that has no items will not expand when clicked. Please provide a bit more details about your scenario so that I am able to help with a suggestion or a sample project.

Greetings,
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
Simon Stahl
Top achievements
Rank 1
answered on 20 Jul 2009, 11:41 AM
Hi Tihomir
the PanelBar displays categories to which the user can relate some items by button click. so even if there are no related items, the category should expand so the user can see that there is nothing yet. then he can relate/add some new items to it.

Simon
0
Tihomir Petkov
Telerik team
answered on 20 Jul 2009, 12:33 PM
Hello Simon,

In this situation, you can put a dummy element, e.g. a TextBlock, with Visibility=Hidden in the empty PanelBarItems so that they can be expanded. Then, when a user decides to add an item to an empty PanelBarItem, you remove the dummy element and add the real items. In the cases when users remove the last item from a category, you can add the dummy element to keep the PanelBarItem expandable.

Please let me know if this workaround works for you.

All the best,
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
Simon Stahl
Top achievements
Rank 1
answered on 20 Jul 2009, 06:44 PM
Hi Tihomir

thanks for your answer. but, actually that sound more complicated than just expand it by myself in the code. I cache now the last selected PanelBarItem, so i can close it later.
private RadPanelBarItem lastSelectedItem = null
private void RadPanelBar_Selected(object sender, RadRoutedEventArgs e) { 
    RadPanelBarItem selItem = e.OriginalSource as RadPanelBarItem; 
 
    if (selItem.Items.Count == 0) 
        selItem.IsExpanded = true
 
    if (lastSelectedItem != null
        lastSelectedItem.IsExpanded = false
 
    lastSelectedItem = selItem; 
this works actually quite well, I just thought that there might be a better way. but obviously there is none, so I'm Ok with this workaround.

thank you anyway for your effort!

greetings Simon
Tags
PanelBar
Asked by
Simon Stahl
Top achievements
Rank 1
Answers by
Tihomir Petkov
Telerik team
Simon Stahl
Top achievements
Rank 1
Share this question
or