Inheritance: IComparable
Ejemplo n.º 1
0
 private void AddFilter(String property, FilterValue value, Button button)
 {
     if (currentFilters.ContainsKey(property))
     {
         currentFilters.Remove(property);
     }
     currentFilters.Add(property, new FilterStruct(property, button, new FilterItem[] { new FilterItem(value) }));
 }
Ejemplo n.º 2
0
        public int CompareTo(object obj)
        {
            FilterValue value = obj as FilterValue;

            return(this.MinValue.CompareTo(value.MinValue));
        }
Ejemplo n.º 3
0
 private void AddFilter(String property, FilterValue value, Button button)
 {
     if (currentFilters.ContainsKey(property))
     {
         currentFilters.Remove(property);
     }
     currentFilters.Add(property, new FilterStruct(property, button, new FilterItem[] { new FilterItem(value) }));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles the button click on the ok button for filtered
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFixedOk_Click(object sender, RoutedEventArgs e)
        {
            Button   btnOk          = (Button)sender;
            ListView filterListView = (ListView)btnOk.Tag;

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

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

            object selectedValue = null;

            foreach (object o in filterListView.Items)
            {
                var item = (FilterItem)o;

                if (item.IsChecked)
                {
                    selectedValue = o;
                }
            }

            if (selectedValue is FilterItem)
            {
                FilterValue value = (FilterValue)(selectedValue as FilterItem).Item;

                if (value.Text == "All")
                {
                    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)UIHelpers.FindVisualElement(header, "filterButton");
                    button.ContentTemplate = (DataTemplate)dictionary["filterButtonActiveTemplate"];

                    if (FilterButtonActiveStyle != null)
                    {
                        button.Style = FilterButtonActiveStyle;
                    }
                    AddFilter(currentFilterProperty, value, button);
                    //AddFilters(currentFilterProperty, items.ToArray(), button);
                    ApplyCurrentFilters();
                }
                // navigate up to the popup and close it
                Popup popup = (Popup)UIHelpers.FindElementOfTypeUp(filterListView, typeof(Popup));
                popup.IsOpen = false;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Applies the current filter to the list which is being viewed
        /// </summary>
        private void ApplyCurrentFilters()
        {
            if (currentFilters.Count == 0)
            {
                Items.Filter = null;
                return;
            }

            // construct a filter and apply it
            Items.Filter = delegate(object item)
            {
                // when applying the filter to each item, iterate over all of
                // the current filters
                bool match = true;
                foreach (FilterStruct filter in currentFilters.Values)
                {
                    // obtain the value for this property on the item under test
                    //PropertyDescriptor filterPropDesc = TypeDescriptor.GetProperties(typeof(object))[filter.property];
                    object itemValue = getPropertyValue(item, filter.property);// filterPropDesc.GetValue((object)item);

                    if (itemValue != null)
                    {
                        Boolean isFilterMatch = false;
                        // check to see if it meets our filter criteria
                        foreach (FilterItem value in filter.values)
                        {
                            if (value.Item is FilterValue)
                            {
                                FilterValue fValue = value.Item as FilterValue;

                                double num;
                                if (double.TryParse(itemValue.ToString(), out num))
                                {
                                    if (num >= fValue.MinValue && num <= fValue.MaxValue)
                                    {
                                        isFilterMatch = true;
                                    }
                                }
                            }
                            else
                            {
                                if (itemValue.Equals(value.Item))
                                {
                                    isFilterMatch = true;
                                }
                            }
                        }

                        if (!isFilterMatch)
                        {
                            match = false;
                        }
                    }
                    else
                    {
                        if (filter.values.ToList().Exists(v => v.Item != null))
                        {
                            match = false;
                        }
                    }
                }
                return(match);
            };
        }