using System.Windows.Controls;
using System.Windows.Data;

namespace MainTestApplication
{
    public partial class Filtering : UserControl
    {
        public Filtering()
        {
            InitializeComponent();
            // create "Customers" data view and bind it to grid
            BindGrid();
            // store sample description in Tag property
            Tag =
                "This demo shows how to enable column filtering. Users may click a drop-down " +
                "on the column headers to set up filters. Active filters are indicated by an icon " +
                " on the column header. Filters may be used in bound and unbound modes.";
        }

        private void BindGrid()
        {
            // create PagedCollectionView used as a data source for the
            // FlexGrid
            var data = Customer.GetCustomerList(100);
            var view = new PagedCollectionView(data);
            using (view.DeferRefresh())
            {
                view.GroupDescriptions.Clear();
                view.GroupDescriptions.Add(new PropertyGroupDescription("Country"));
                view.GroupDescriptions.Add(new PropertyGroupDescription("Active"));
                var gd = view.GroupDescriptions[0] as PropertyGroupDescription;
                gd.Converter = new CountryInitialConverter();
            }

            // bind grid to PagedCollectionView
            _flexFilter.ItemsSource = view;
        }
    }
}
