Exemple #1
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            // ensure that the custom inactive style is applied
            if (FilterButtonInactiveStyle != null)
            {
                List <FrameworkElement> columnHeaders = UIHelpers.FindElementsOfType(this, typeof(GridViewColumnHeader));

                foreach (FrameworkElement columnHeader in columnHeaders)
                {
                    Button button = (Button)UIHelpers.FindElementOfType(columnHeader, typeof(Button));
                    if (button != null)
                    {
                        button.Style = FilterButtonInactiveStyle;
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Handles the ShowFilter command to populate the filter list and display the popup
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ShowFilterCommand(object sender, ExecutedRoutedEventArgs e)
        {
            Button button = e.OriginalSource as Button;

            if (button != null)
            {
                // navigate up to the header
                GridViewColumnHeader header = (GridViewColumnHeader)UIHelpers.FindElementOfTypeUp(button, typeof(GridViewColumnHeader));

                // then down to the popup
                Popup popup = (Popup)UIHelpers.FindElementOfType(header, typeof(Popup));

                if (popup != null)
                {
                    // find the property name that we are filtering
                    SortableGridViewColumn column = (SortableGridViewColumn)header.Column;
                    String propertyName           = column.SortPropertyName;


                    // clear the previous filter
                    if (filterList == null)
                    {
                        filterList = new ArrayList();
                    }
                    filterList.Clear();

                    // if this property is currently being filtered, provide an option to clear the filter.
                    if (IsPropertyFiltered(propertyName))
                    {
                        filterList.Add(new FilterItem("Clear"));
                    }
                    else
                    {
                        bool containsNull = false;

                        //PropertyDescriptor filterPropDesc = TypeDescriptor.GetProperties(typeof(Airport))[propertyName];



                        // iterate over all the objects in the list
                        foreach (Object item in Items)
                        {
                            object value = getPropertyValue(item, propertyName);


                            if (value != null)
                            {
                                FilterItem filterItem = new FilterItem(value as IComparable);

                                Boolean contains = filterList.Cast <FilterItem>().ToList().Exists(i => i.Item.ToString() == filterItem.Item.ToString());

                                if (!filterList.Contains(filterItem) && !contains)
                                {
                                    filterList.Add(filterItem);
                                }
                            }
                            else
                            {
                                containsNull = true;
                            }
                        }

                        filterList.Sort();

                        if (containsNull)
                        {
                            filterList.Add(new FilterItem(null));
                        }
                    }

                    // open the popup to display this list
                    popup.DataContext = filterList;
                    CollectionViewSource.GetDefaultView(filterList).Refresh();
                    popup.IsOpen = true;

                    // connect to the selection change event
                    ListView listView = UIHelpers.FindChild <ListView>(popup.Child, "filterList");
                    //listView.SelectionChanged += SelectionChangedHandler;

                    Button btnOk = UIHelpers.FindChild <Button>(popup.Child, "btnOk");
                    btnOk.Click += btnOk_Click;

                    Button btnCancel = UIHelpers.FindChild <Button>(popup.Child, "btnCancel");
                    btnCancel.Click += btnCancel_Click;
                }
            }
        }