How to change default behaviour

4 posts, 0 answers
  1. Berthold
    Berthold avatar
    38 posts
    Member since:
    Jul 2010

    Posted 11 Oct 2010 Link to this post

    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



      
      
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 14 Oct 2010 Link to this post

    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
  3. DevCraft banner
  4. Berthold
    Berthold avatar
    38 posts
    Member since:
    Jul 2010

    Posted 19 Oct 2010 Link to this post

    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

     

     

     

     

     

     

  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 20 Oct 2010 Link to this post

    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
Back to Top