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

Collapse one before expanding another

1 Answer 25 Views
ExpanderControl
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Shantimohan
Top achievements
Rank 1
Shantimohan asked on 04 Jul 2013, 02:12 AM
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
        {
            get
            {
                return this.isExpanded;
            }
            set
            {
                if (this.isExpanded != value)
                {
                    this.isExpanded = value;
                    this.OnPropertyChanged("IsExpanded");
                }
            }
        }
 
XAML:
                        <telerikPrimitives:RadExpanderControl ExpandableContent="{Binding}"
                                                              Content="{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;
            }
        }

1 Answer, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 04 Jul 2013, 07:42 AM
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.

Regards,
Deyan
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
ExpanderControl
Asked by
Shantimohan
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Share this question
or