Collapse one before expanding another

Thread is closed for posting
2 posts, 0 answers
  1. Shantimohan
    Shantimohan avatar
    42 posts
    Member since:
    Jul 2012

    Posted 03 Jul 2013 Link to this post

    Hi Telerik,

    I have seen the other posting on same subject. But it is not working. Here is the code that I tried.
    // property added to CollectionDataItemViewModel
            private bool isExpanded;
            public bool IsExpanded
                    return this.isExpanded;
                    if (this.isExpanded != value)
                        this.isExpanded = value;
                            <telerikPrimitives:RadExpanderControl ExpandableContent="{Binding}"
                                                                  IsExpanded="{Binding IsExpanded}"
                                                                  BorderBrush="{StaticResource PhoneSubtleBrush}">
                                 ... ... ... ... ...
            private void rdlbMain_SelectionChanged(object sender, SelectionChangedEventArgs e)
                if (e.RemovedItems.Count > 0)
                    ViewModels.CollectionDataItemViewModel item = (ViewModels.CollectionDataItemViewModel)e.RemovedItems[0];
                    item.IsExpanded = false;
  2. Deyan
    Deyan avatar
    2147 posts

    Posted 04 Jul 2013 Link to this post

    Hello Shantimohan,

    Thanks for writing.

    The SelectionChanged event does not guarantee you that you will get access to all previously expanded items.

    Here's an approach that should be working correctly:

    private EmailMessage lastExpandedItem;
    private void RadExpanderControl_ExpandedStateChanged(object sender, ExpandedStateChangedEventArgs e)
        if (e.IsExpanded)
            if (lastExpandedItem != null)
                lastExpandedItem.IsExpanded = false;
            this.lastExpandedItem = (sender as RadExpanderControl).DataContext as EmailMessage;

    What I am doing is handling the ExpandedStateChanged event of the RadExpanderControl in my item template. I have a lastExpandedItem field that is the same type as my business objects. Each time the ExpandedStateChanged event is fired, I check if the last expanded item has been initialized and set its IsExpanded property to false. After that I reinitialize this field with the new item that has been expanded.

    I hope this is helpful.

    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Back to Top