How to trigger .NET MAUI Expander only by tapping a specific element in header?
This article illustrates triggering the expander expand/collapse action only when tapping a specific element within the header for .NET MAUI SfExpander. In this example, we will trigger the expander expand/collapse action only when tapping the specific element within the header.
Initialize the SfExpander with the required properties. Then, in the expander header, you can add the specific element here for example added the Image
with GestureRecognizers
.This setup allows you to manually toggle the expansion by tapping the image, ensuring that the expand/collapse action is activated only when the image is tapped, rather than any area of the header.
XAML:
<ContentPage.Content>
<StackLayout Padding="20">
<syncfusion:SfExpander x:Name="expander">
<syncfusion:SfExpander.Header>
<StackLayout Orientation="Horizontal">
<Label Text="Header"
VerticalOptions="Center"
HorizontalOptions="StartAndExpand"/>
<Image Source="dotnet_bot.png"
WidthRequest="200"
HeightRequest="50"
VerticalOptions="Center"
HorizontalOptions="End">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="OnExpandIconTapped"/>
</Image.GestureRecognizers>
</Image>
</StackLayout>
</syncfusion:SfExpander.Header>
<syncfusion:SfExpander.Content>
<Label Text="Expander Content"/>
</syncfusion:SfExpander.Content>
</syncfusion:SfExpander>
</StackLayout>
</ContentPage.Content>
MainPage.xaml.cs
private void OnExpandIconTapped(object sender, TappedEventArgs e)
{
expander.IsExpanded = !expander.IsExpanded;
}
Download the complete sample from GitHub
Conclusion
I hope you enjoyed learning how to trigger .NET MAUI Expander only by tapping a specific element in header.
You can refer to our .NET MAUI Expander feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications.
For current customers, check out our components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!