Expand empty PanelBarItem

5 posts, 0 answers
  1. Simon Stahl
    Simon Stahl avatar
    10 posts
    Member since:
    Apr 2009

    Posted 18 Jul 2009 Link to this post

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

    Posted 20 Jul 2009 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Simon Stahl
    Simon Stahl avatar
    10 posts
    Member since:
    Apr 2009

    Posted 20 Jul 2009 Link to this post

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

    Posted 20 Jul 2009 Link to this post

    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.
  6. Simon Stahl
    Simon Stahl avatar
    10 posts
    Member since:
    Apr 2009

    Posted 20 Jul 2009 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready