Back to Devexpress

AccordionControl.CanSelectItem Event

wpf-devexpress-dot-xpf-dot-accordion-dot-accordioncontrol-bd878e89.md

latest4.7 KB
Original Source

AccordionControl.CanSelectItem Event

Occurs when an end user moves the mouse over an item or selects items with the keyboard and allows you to prevent particular accordion items from being selected.

Namespace : DevExpress.Xpf.Accordion

Assembly : DevExpress.Xpf.Accordion.v25.2.dll

NuGet Package : DevExpress.Wpf.Accordion

Declaration

csharp
public event EventHandler<CanSelectItemEventArgs> CanSelectItem
vb
Public Event CanSelectItem As EventHandler(Of CanSelectItemEventArgs)

Event Data

The CanSelectItem event's data class is CanSelectItemEventArgs. The following properties provide information specific to this event:

PropertyDescription
CanSelectGets or sets whether the processed accordion item can be selected.
ItemGets the processed item.

Remarks

In the event handler, use the Item property to get the processed item. To prevent this item from being selected, set the CanSelect property to false.

In Bound Mode

In bound mode, the Item property returns a bound data object.

The code sample below demonstrates how to prevent an item with the “Application Settings” caption from being selected.

xaml
<Window ...
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
        xmlns:dxa="http://schemas.devexpress.com/winfx/2008/xaml/accordion">
    <Grid>
        <dxa:AccordionControl
            ItemsSource="{Binding AppMenu.MenuItems}"
            DisplayMemberPath="Caption"
            ChildrenPath="SubItems"
            CanSelectItem="AccordionControl_CanSelectItem" />
    </Grid>
</Window>
csharp
private void AccordionControl_CanSelectItem(object sender, DevExpress.Xpf.Accordion.CanSelectItemEventArgs e) {
    MenuItem item = (MenuItem)e.Item;
    if (item.Caption.Equals("Application Settings")) {
        e.CanSelect = false;
    }
}
vb
Private Sub AccordionControl_CanSelectItem(ByVal sender As Object, ByVal e As DevExpress.Xpf.Accordion.CanSelectItemEventArgs)
    Dim item As MenuItem = CType(e.Item, MenuItem)

    If item.Caption.Equals("Application Settings") Then
        e.CanSelect = False
    End If
End Sub

In Unbound Mode

In unbound mode, the Item property returns an AccordionItem.

The code sample below demonstrates how to prevent an item with the “Application Settings” header from being selected.

xaml
<Window ...
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
        xmlns:dxa="http://schemas.devexpress.com/winfx/2008/xaml/accordion">
    <Grid>
        <dxa:AccordionControl
            CanSelectItem="AccordionControl_CanSelectItem" >
            <dxa:AccordionItem Header="Start Page"/>
            <dxa:AccordionItem Header="Preferences">
                <dxa:AccordionItem Header="Account Info"/>
                <dxa:AccordionItem Header="Application Settings"/>
            </dxa:AccordionItem>
            <dxa:AccordionItem Header="About"/>
        </dxa:AccordionControl>
    </Grid>
</Window>
csharp
using DevExpress.Xpf.Accordion;
...

private void AccordionControl_CanSelectItem(object sender, CanSelectItemEventArgs e) {
    AccordionItem item = (AccordionItem)e.Item;
    if (item.Header.Equals("Application Settings")) {
        e.CanSelect = false;
    }
}
...
vb
Imports DevExpress.Xpf.Accordion
...

Private Sub AccordionControl_CanSelectItem(ByVal sender As Object, ByVal e As CanSelectItemEventArgs)
    Dim item As AccordionItem = CType(e.Item, AccordionItem)

    If item.Header.Equals("Application Settings") Then
        e.CanSelect = False
    End If
End Sub
...

See Also

CanSelect

AccordionControl Class

AccordionControl Members

DevExpress.Xpf.Accordion Namespace