Articles in this section
Category / Section

How to override the key events for the SfAccordionItem?

1 min read

You can override the key events for the SfAccordionItem. The following code example describes how to disable the Enter Key press behavior, by overriding the KeyDown event. In the code, a local control AccordionItem is created that inherits the SfAccordionItem class. By using the AccordionItem, you can override the KeyDown event and disable the Enter Key press behavior.

MainPage.xaml

<Page
    x:Class="SfAccordionKeyDown.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using: SfAccordionKeyDown" RequestedTheme="Light"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:layout="using:Syncfusion.UI.Xaml.Controls.Layout"
    mc:Ignorable="d">
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <layout:SfAccordion x:Name="accordion" Height="700" Width="650" Margin="100">
            <local:AccordionItem Header="Item1" Content="Content"/>
            <local:AccordionItem Header="Item2" Content="Content"/>
            <local:AccordionItem Header="Item3" Content="Content"/>
            <local:AccordionItem Header="Item4" Content="Content"/>
        </layout:SfAccordion>
    </Grid>
</Page>

 

MainPage.xaml.cs

public class AccordionItem:SfAccordionItem
    {
        protected override void OnKeyDown(KeyRoutedEventArgs e)
        {
            if (e.Key != VirtualKey.Enter)
                base.OnKeyDown(e);
        }
    }

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied