示例#1
0
        /// <summary>
        /// Handles the button click on the cancel button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Button   btnCancel      = (Button)sender;
            ListView filterListView = (ListView)btnCancel.Tag;

            Popup popup = (Popup)UIHelpers.FindElementOfTypeUp(filterListView, typeof(Popup));

            popup.IsOpen = false;
        }
示例#2
0
        /// <summary>
        /// Handles the button click on the ok button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_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;

            var items = new List <FilterItem>();

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

                if (item.IsChecked)
                {
                    items.Add(item);
                }
            }

            if (items.Exists(i => i.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)UIHelpers.FindVisualElement(header, "filterButton");
                button.ContentTemplate = (DataTemplate)dictionary["filterButtonActiveTemplate"];

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

                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;
        }
示例#3
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)UIHelpers.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)UIHelpers.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)UIHelpers.FindElementOfTypeUp(filterListView, typeof(Popup));

            popup.IsOpen = false;
        }
示例#4
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;
                }
            }
        }