Esempio n. 1
0
        /// <summary>
        /// Handles the selection change event from the filter popup
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectionChangedHandler(object sender, SelectionChangedEventArgs e)
        {
            // obtain the term to filter for
            ListView   filterListView = (ListView)sender;
            FilterItem filterItem     = (FilterItem)filterListView.SelectedItem;

            // navigate up to the header to obtain the filter property name
            GridViewColumnHeader header = (GridViewColumnHeader)Helpers.FindElementOfTypeUp(filterListView, typeof(GridViewColumnHeader));

            SortableGridViewColumn column = (SortableGridViewColumn)header.Column;
            String currentFilterProperty  = column.SortPropertyName;

            if (filterItem == null)
            {
                return;
            }

            // determine whether to clear the filter for this column
            if (filterItem.ItemView.Equals("[clear]"))
            {
                if (currentFilters.ContainsKey(currentFilterProperty))
                {
                    FilterStruct filter = (FilterStruct)currentFilters[currentFilterProperty];
                    //filter.button.ContentTemplate = (DataTemplate)dictionary["filterButtonInactiveTemplate"];
                    //if (FilterButtonInactiveStyle != null)
                    //{
                    //    filter.button.Style = FilterButtonInactiveStyle;
                    //}
                    currentFilters.Remove(currentFilterProperty);
                }

                ApplyCurrentFilters();
            }
            else
            {
                // find the button and apply the active style
                Button button = (Button)Helpers.FindVisualElement(header, "filterButton");
                //button.ContentTemplate = (DataTemplate)dictionary["filterButtonActiveTemplate"];

                //if (FilterButtonActiveStyle != null)
                //{
                //    button.Style = FilterButtonActiveStyle;
                //}

                AddFilter(currentFilterProperty, filterItem, button);
                ApplyCurrentFilters();
            }

            // navigate up to the popup and close it
            Popup popup = (Popup)Helpers.FindElementOfTypeUp(filterListView, typeof(Popup));

            popup.IsOpen = false;
        }
Esempio n. 2
0
        public override bool Equals(object obj)
        {
            FilterItem otherItem = obj as FilterItem;

            if (otherItem != null && this.Item != null)
            {
                if (otherItem.Item.ToString() == this.Item.ToString())
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
        public int CompareTo(object obj)
        {
            FilterItem otherFilterItem = (FilterItem)obj;

            if (this.Item == null && obj == null)
            {
                return(0);
            }
            else if (otherFilterItem.Item != null && this.Item != null)
            {
                return(((IComparable)item).CompareTo((IComparable)otherFilterItem.item));
            }
            else
            {
                return(-1);
            }
        }
Esempio n. 4
0
        private void ShowFilterCommand(object sender, ExecutedRoutedEventArgs e)
        {
            Button button = e.OriginalSource as Button;

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

                if (header == null)
                {
                    return;
                }

                // then down to the popup
                Popup popup = (Popup)Helpers.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(Log))[propertyName];
                        PropertyDescriptor filterPropDesc = TypeDescriptor.GetProperties(FilterType.GetType())[propertyName];
                        // iterate over all the objects in the list
                        foreach (Object item in Items)
                        {
                            object value = filterPropDesc.GetValue(item);
                            if (value != null)
                            {
                                FilterItem filterItem = new FilterItem(value as IComparable);
                                if (!filterList.Contains(filterItem))
                                {
                                    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 = (ListView)popup.Child;
                    listView.SelectionChanged += SelectionChangedHandler;
                }
            }
        }
Esempio n. 5
0
 public FilterStruct(String property, Button button, FilterItem value)
 {
     this.value    = value;
     this.button   = button;
     this.property = property;
 }