Is there an event when the user expands/collapses a card?

2 Answers 63 Views
CardView
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
Peter asked on 04 Mar 2022, 08:02 AM

Hello,

I am using the CardView-Control. Is there an event when the user expands/collapses a card?

regards

Tobias

2 Answers, 1 is accepted

Sort by
1
Accepted
Stenly
Telerik team
answered on 08 Mar 2022, 08:08 AM

Hello Tobias,

I have provided an answer in this forum thread, regarding this requirement, so, could you give the proposed suggestion a try and let me know how it goes? In addition, I have logged a new feature request in our feedback portal, to allow intercepting the expanding and collapsing of a RadCardViewItem element. You could vote for it, as well as follow it, to get notified via e-mail when its status gets changed.

I hope the provided information is of help to you.

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Stenly
Telerik team
answered on 10 Mar 2022, 11:28 AM

Hello Tobias,

I am writing this reply to follow up on an alternative approach, without having to extract the default control template. Basically, you could subscribe to the Loaded event of the RadCardView control, and add two new event handlers via the AddHandler method.

For the first handler, which will be responsible for occurring when expanding, pass as a first argument RadExpander.ExpandedEvent. As a second parameter, create a new RoutedEventHandler instance with a method, which will fire the custom logic when the internal RadExpander element of the current RadCardView is getting expanded.

For the second added event handler, which will be responsible for the collapsing logic, the same approach as the abovementioned one could be used.

The following code snippet shows this approach's implementation:

private void CardView_Loaded(object sender, RoutedEventArgs e)
{
    this.cardView.AddHandler(RadExpander.ExpandedEvent, new RoutedEventHandler(Expanded));
    this.cardView.AddHandler(RadExpander.CollapsedEvent, new RoutedEventHandler(Collapsed));
}

private void Expanded(object sender, RoutedEventArgs e)
{
    var expander = e.OriginalSource as RadExpander;
    //Get clicked CardViewItem element
    var cardViewItem = expander.ParentOfType<RadCardViewItem>();
}

private void Collapsed(object sender, RoutedEventArgs e)
{
    var expander = e.OriginalSource as RadExpander;
    //Get clicked CardViewItem element
    var cardViewItem = expander.ParentOfType<RadCardViewItem>();
}

Through the ParentOfType extension method, the current RadCardViewItem element could be retrieved. The ParentOfType method's logic is documented in our Visual Tree Helpers article.

With that said, I hope this would be a suitable substitute for the first approach, which I have provided.

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
CardView
Asked by
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Stenly
Telerik team
Share this question
or