wpf-devexpress-dot-xpf-dot-accordion-dot-accordioncontrol-590e895a.md
Gets or sets whether to synchronize the AccordionControl with the collection view data source. This is a dependency property.
Namespace : DevExpress.Xpf.Accordion
Assembly : DevExpress.Xpf.Accordion.v25.2.dll
NuGet Package : DevExpress.Wpf.Accordion
public bool AllowCollectionView { get; set; }
Public Property AllowCollectionView As Boolean
| Type | Default | Description |
|---|---|---|
| Boolean | false |
true to synchronize the AccordionControl with the collection view data source; otherwise, false.
|
You can bind the AccordionControl to an ICollectionView and specify the current record, filter, sort, and group options at the data source level.
If the AllowCollectionView property is set to false and an ICollectionView is used as a data source, the AccordionControl transforms the ICollectionView to a plain list. In this instance, filter, group, and sort rules defined in the ICollectionView are ignored.
AccordionControl child items ignore ICollectionView settings if you bind the parent item’s ItemsSource property to an ICollectionView to obtain these child items (for example, if you use Hierarchical Data Templates or manually define parent items).
This example demonstrates how to bind the AccordionControl to a collection view and synchronize the selected item with the collection view.
View:
<Window x:Class="CollectionViewSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxa="http://schemas.devexpress.com/winfx/2008/xaml/accordion"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
dx:ThemeManager.Theme="Office2019Colorful"
xmlns:local="clr-namespace:CollectionViewSample"
DataContext="{dxmvvm:ViewModelSource local:ViewModel}"
Title="Products" Height="450" Width="500">
<Window.Resources>
<CollectionViewSource Source="{Binding Products}" x:Key="Products" >
<CollectionViewSource.SortDescriptions>
<componentModel:SortDescription PropertyName="ProductName" Direction="Ascending"/>
</CollectionViewSource.SortDescriptions>
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Category"/>
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</Window.Resources>
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<dxe:ListBoxEdit ItemsSource="{Binding Source={StaticResource Products}}"
DisplayMember="ProductName"
AllowCollectionView="True" IsSynchronizedWithCurrentItem="True">
<dxe:ListBoxEdit.GroupStyle>
<x:Static Member="GroupStyle.Default"/>
</dxe:ListBoxEdit.GroupStyle>
</dxe:ListBoxEdit>
<dxa:AccordionControl Grid.Column="1" ItemsSource="{Binding Source={StaticResource Products}}"
AutoExpandAllItems="True" ChildrenPath="Items"
AllowCollectionView="True" IsSynchronizedWithCurrentItem="True" ShowSearchControl="True">
<dxa:AccordionControl.ItemContainerStyle>
<Style TargetType="dxa:AccordionItem">
<Style.Triggers>
<Trigger Property="ItemLevel" Value="1">
<Setter Property="Header" Value="{Binding ProductName}"/>
</Trigger>
</Style.Triggers>
</Style>
</dxa:AccordionControl.ItemContainerStyle>
</dxa:AccordionControl>
</Grid>
</Window>
View Model:
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace CollectionViewSample {
public class ViewModel {
public virtual ReadOnlyCollection<Product> Products { get; set; }
public ViewModel() {
Products = new ReadOnlyCollection<Product>(CreateProducts());
}
List<Product> CreateProducts() {
var result = new List<Product> {
new Product("Queso Manchego La Pastora", "Cheeses"),
new Product("Gorgonzola Telino", "Cheeses"),
new Product("Chai", "Beverages"),
new Product("Outback Lager", "Beverages"),
new Product("Mozzarella di Giovannia", "Cheeses"),
new Product("Geitost", "Cheeses"),
new Product("Chartreuse verte", "Beverages"),
new Product("Ipoh Coffee", "Beverages")
};
return result;
}
}
public class Product {
public Product(string productName, string category) {
ProductName = productName;
Category = category;
}
public string ProductName { get; set; }
public string Category { get; set; }
public override string ToString() {
return ProductName;
}
}
}
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Namespace CollectionViewSample
Public Class ViewModel
Public Overridable Property Products As ReadOnlyCollection(Of Product)
Public Sub New()
Products = New ReadOnlyCollection(Of Product)(CreateProducts())
End Sub
Private Function CreateProducts() As List(Of Product)
Dim result = New List(Of Product) From {
New Product("Queso Manchego La Pastora", "Cheeses"),
New Product("Gorgonzola Telino", "Cheeses"),
New Product("Chai", "Beverages"),
New Product("Outback Lager", "Beverages"),
New Product("Mozzarella di Giovannia", "Cheeses"),
New Product("Geitost", "Cheeses"),
New Product("Chartreuse verte", "Beverages"),
New Product("Ipoh Coffee", "Beverages")
}
Return result
End Function
End Class
Public Class Product
Public Sub New(ByVal productName As String, ByVal category As String)
ProductName = productName
Category = category
End Sub
Public Property ProductName As String
Public Property Category As String
Public Overrides Function ToString() As String
Return ProductName
End Function
End Class
End Namespace
See Also