Ejemplo n.º 1
0
        private void ListViewDragDelta(Object sender, DragDeltaEventArgs e)
        {
            Thumb senderAsThumb         = e.OriginalSource as Thumb;
            GridViewColumnHeader header = senderAsThumb.TemplatedParent as GridViewColumnHeader;

            if (header == null)
            {
                return;
            }
            ListViewExColumn column = header.Column as ListViewExColumn;

            if (column != null)
            {
                Double minWidth = column.MinWidth;
                Double maxWidth = column.MaxWidth;

                if (Double.IsNaN(minWidth) == false)
                {
                    if (header.Column.ActualWidth < minWidth)
                    {
                        header.Column.Width = minWidth;
                    }
                }

                if (Double.IsNaN(maxWidth) == false)
                {
                    if (header.Column.ActualWidth > maxWidth)
                    {
                        header.Column.Width = maxWidth;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void SetConfig(ListViewExConfig config)
        {
            for (int i = 0; i < PART_gridView.Columns.Count; i++)
            {
                foreach (ColumnConfig item in config.Columns)
                {
                    if (i == item.Index)
                    {
                        ListViewExColumn column = (ListViewExColumn)PART_gridView.Columns[i];

                        if (item.Visible == true)
                        {
                            column.SaveWidth = item.Width;
                            column.Visible   = true;
                            column.Width     = item.Width;
                        }
                        else
                        {
                            column.SaveWidth = item.Width;
                            column.Visible   = false;
                        }
                    } // end if (найдена текущая колонка
                }     // end foreach (перебор конфигурации колонок)
            }         // end foreach (перебор текущих колонок)
        }
Ejemplo n.º 3
0
        private ListViewExConfig GetConfig()
        {
            ListViewExConfig config = new ListViewExConfig();

            for (int i = 0; i < PART_gridView.Columns.Count; i++)
            {
                ListViewExColumn column = (ListViewExColumn)PART_gridView.Columns[i];
                ColumnConfig     item   = new ColumnConfig();

                item.Index = i;
                item.Name  = (String)column.Header;

                if (column.Visible == true)
                {
                    item.Visible = true;
                    item.Width   = column.ActualWidth;
                }
                else
                {
                    item.Visible = false;
                    item.Width   = column.SaveWidth;
                }

                config.Columns.Add(item);
            }

            return(config);
        }
Ejemplo n.º 4
0
        private void SetCheckContextMenu(ListViewExColumn column, Boolean value)
        {
            foreach (MenuItem item in _headerMenu.Items)
            {
                ListViewExColumn itemColumn = (ListViewExColumn)item.Tag;

                if (column == itemColumn)
                {
                    item.IsChecked = value;
                    return;
                }
            }
        }
Ejemplo n.º 5
0
        private void ColumnHeaderClickedHandler(Object sender, RoutedEventArgs e)
        {
            GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader;
            ListSortDirection    direction;

            if (headerClicked != null)
            {
                if (_lastHeaderClicked != null)
                {
                    _lastHeaderClicked.Column.HeaderTemplate = null;
                }

                if (headerClicked != _lastHeaderClicked)
                {
                    direction = ListSortDirection.Ascending;
                }
                else
                {
                    if (_lastDirection == ListSortDirection.Ascending)
                    {
                        direction = ListSortDirection.Descending;
                    }
                    else
                    {
                        direction = ListSortDirection.Ascending;
                    }
                }

                ListViewExColumn column = headerClicked.Column as ListViewExColumn;

                if (column != null)
                {
                    ColumnSort(column, direction);

                    if (direction == ListSortDirection.Ascending)
                    {
                        headerClicked.Column.HeaderTemplate =
                            Resources["HeaderTemplateArrowUp"] as DataTemplate;
                    }
                    else
                    {
                        headerClicked.Column.HeaderTemplate =
                            Resources["HeaderTemplateArrowDown"] as DataTemplate;
                    }

                    _lastHeaderClicked = headerClicked;
                    _lastDirection     = direction;
                }
            }
        }
Ejemplo n.º 6
0
        private void OnHeaderMenuClick(Object sender, RoutedEventArgs e)
        {
            MenuItem item = sender as MenuItem;

            if (item != null)
            {
                ListViewExColumn column = (ListViewExColumn)item.Tag;

                if (item.IsChecked)
                {
                    column.Visible = true;
                }
                else
                {
                    column.Visible = false;
                }

                e.Handled = true;
            }
        }
Ejemplo n.º 7
0
 private void ColumnSort(ListViewExColumn column, ListSortDirection direction)
 {
     if (_sorter != null)
     {
         _sorter.Direction  = direction;
         _sorter.ColumnName = column.Name;
         ListCollectionView view = (ListCollectionView)CollectionViewSource.GetDefaultView(PART_listView.ItemsSource);
         view.CustomSort = _sorter;
         view.Refresh();
     }
     else
     {
         ICollectionView view = CollectionViewSource.GetDefaultView(PART_listView.ItemsSource);
         if (view != null)
         {
             view.SortDescriptions.Clear();
             SortDescription sortDesc = new SortDescription(column.Header as String, direction);
             view.SortDescriptions.Add(sortDesc);
             view.Refresh();
         }
     }
 }