I am using the CardView-Control. Is there an event when the user expands/collapses a card?
regards
Tobias
2 Answers, 1 is accepted
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:
privatevoidCardView_Loaded(object sender, RoutedEventArgs e)
{
this.cardView.AddHandler(RadExpander.ExpandedEvent, new RoutedEventHandler(Expanded));
this.cardView.AddHandler(RadExpander.CollapsedEvent, new RoutedEventHandler(Collapsed));
}
privatevoidExpanded(object sender, RoutedEventArgs e)
{
var expander = e.OriginalSource as RadExpander;
//Get clicked CardViewItem elementvar cardViewItem = expander.ParentOfType<RadCardViewItem>();
}
privatevoidCollapsed(object sender, RoutedEventArgs e)
{
var expander = e.OriginalSource as RadExpander;
//Get clicked CardViewItem elementvar 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.