Пример #1
0
        private static void CreateColumns(GridView gridView, object view)
        {
            ObservableCollection<ColumnDescriptor> COLS = (ObservableCollection<ColumnDescriptor>)view;

            gridView.Columns.Clear();

            for (int i = 0; i < COLS.Count; i++)
            {

                TreeGridViewColumn column = new TreeGridViewColumn();
                column.Header = COLS[i].HeaderText;
                column.ColumnIndex = i;
                column.SortProperty = COLS[i].DisplayMember;
                column.SortStyle = "FamilyDataGridViewColumnHeader";
                DataTemplate d = new DataTemplate();
                if (i == 0)
                {

                    FrameworkElementFactory borderFactory = new FrameworkElementFactory(typeof(Border));
                    borderFactory.SetValue(Border.MarginProperty, new Thickness(-6, -3, -6, -3));

                    if (GetHorizontalLines(gridView))
                        borderFactory.SetValue(Border.BorderThicknessProperty, new Thickness(0, 1, 0, 0));

                    borderFactory.SetValue(Border.BorderBrushProperty, System.Windows.Media.Brushes.Black);

                    FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(StackPanel));
                    spFactory.SetValue(StackPanel.MarginProperty, new Thickness(6, 2, 6, 2));

                    spFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
                    spFactory.SetValue(StackPanel.ToolTipProperty, COLS[i].align.ToString());
                    FrameworkElementFactory RowExpanderFactory = new FrameworkElementFactory(typeof(RowExpander));
                    FrameworkElementFactory TextblockFactory = new FrameworkElementFactory(typeof(TextBlock));
                    TextblockFactory.SetBinding(TextBlock.TextProperty, new Binding(COLS[i].DisplayMember));

                    spFactory.AppendChild(RowExpanderFactory);
                    spFactory.AppendChild(TextblockFactory);
                    borderFactory.AppendChild(spFactory);
                    d.VisualTree = borderFactory;
                }
                else
                {

                    FrameworkElementFactory borderFactory = new FrameworkElementFactory(typeof(Border));
                    borderFactory.SetValue(Border.MarginProperty, new Thickness(-6, -3, -6, -3));

                    if (GetHorizontalLines(gridView) && GetVerticalLines(gridView))
                        borderFactory.SetValue(Border.BorderThicknessProperty, new Thickness(1, 1, 0, 0));
                    else if (GetHorizontalLines(gridView))
                        borderFactory.SetValue(Border.BorderThicknessProperty, new Thickness(0, 1, 0, 0));
                    else if (GetVerticalLines(gridView))
                        borderFactory.SetValue(Border.BorderThicknessProperty, new Thickness(1, 0, 0, 0));

                    borderFactory.SetValue(Border.BorderBrushProperty, System.Windows.Media.Brushes.Black);

                    //Border b;
                    //b.Margin
                    FrameworkElementFactory TextblockFactory = new FrameworkElementFactory(typeof(TextBlock));
                    TextblockFactory.SetBinding(TextBlock.TextProperty, new Binding(COLS[i].DisplayMember));
                    TextblockFactory.SetValue(TextBlock.MarginProperty, new Thickness(6, 2, 6, 2));

                    TextblockFactory.SetValue(TextBlock.TextAlignmentProperty, COLS[i].align);
                    TextblockFactory.SetValue(TextBlock.ToolTipProperty, COLS[i].align.ToString());
                    borderFactory.AppendChild(TextblockFactory);
                    d.VisualTree = borderFactory;
                }

                column.CellTemplate = d;
                column.Width = COLS[i].width;

                gridView.Columns.Add(column);

            }
        }
Пример #2
0
        private void ColumnHeader_Click(object sender, RoutedEventArgs e)
        {
            // Make sure the column is really being sorted.
            GridViewColumnHeader header = e.OriginalSource as GridViewColumnHeader;

            if (header != null && header.Role != GridViewColumnHeaderRole.Padding)
            {

                TreeGridViewColumn column = header.Column as TreeGridViewColumn;
                if (column == null)
                    return;

                // See if a new column was clicked, or the same column was clicked.
                if (sortColumn != column)
                {
                    // A new column was clicked.
                    previousSortColumn = sortColumn;
                    sortColumn = column;
                    sortDirection = ListSortDirection.Ascending;
                }
                else
                {
                    // The same column was clicked, change the sort order.
                    previousSortColumn = null;
                    sortDirection = (sortDirection == ListSortDirection.Ascending) ?
                        ListSortDirection.Descending : ListSortDirection.Ascending;
                }

                // Sort the data.
                SortList(column.ColumnIndex);

                // Update the column header based on the sort column and order.
                UpdateHeaderTemplate();
            }
            else if (e.OriginalSource is Button)
            {
                //Filter objfilter = new Filter(ColumnsSource);
                //objfilter.Show();
            }
        }
Пример #3
0
        private static void CreateColumns(GridView gridView, object view)
        {
            ObservableCollection <ColumnDescriptor> COLS = (ObservableCollection <ColumnDescriptor>)view;

            gridView.Columns.Clear();

            for (int i = 0; i < COLS.Count; i++)
            {
                TreeGridViewColumn column = new TreeGridViewColumn();
                column.Header       = COLS[i].HeaderText;
                column.ColumnIndex  = i;
                column.SortProperty = COLS[i].DisplayMember;
                column.SortStyle    = "FamilyDataGridViewColumnHeader";
                DataTemplate d = new DataTemplate();
                if (i == 0)
                {
                    FrameworkElementFactory borderFactory = new FrameworkElementFactory(typeof(Border));
                    borderFactory.SetValue(Border.MarginProperty, new Thickness(-6, -3, -6, -3));

                    if (GetHorizontalLines(gridView))
                    {
                        borderFactory.SetValue(Border.BorderThicknessProperty, new Thickness(0, 1, 0, 0));
                    }

                    borderFactory.SetValue(Border.BorderBrushProperty, System.Windows.Media.Brushes.Black);


                    FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(StackPanel));
                    spFactory.SetValue(StackPanel.MarginProperty, new Thickness(6, 2, 6, 2));

                    spFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
                    spFactory.SetValue(StackPanel.ToolTipProperty, COLS[i].align.ToString());
                    FrameworkElementFactory RowExpanderFactory = new FrameworkElementFactory(typeof(RowExpander));
                    FrameworkElementFactory TextblockFactory   = new FrameworkElementFactory(typeof(TextBlock));
                    TextblockFactory.SetBinding(TextBlock.TextProperty, new Binding(COLS[i].DisplayMember));

                    spFactory.AppendChild(RowExpanderFactory);
                    spFactory.AppendChild(TextblockFactory);
                    borderFactory.AppendChild(spFactory);
                    d.VisualTree = borderFactory;
                }
                else
                {
                    FrameworkElementFactory borderFactory = new FrameworkElementFactory(typeof(Border));
                    borderFactory.SetValue(Border.MarginProperty, new Thickness(-6, -3, -6, -3));

                    if (GetHorizontalLines(gridView) && GetVerticalLines(gridView))
                    {
                        borderFactory.SetValue(Border.BorderThicknessProperty, new Thickness(1, 1, 0, 0));
                    }
                    else if (GetHorizontalLines(gridView))
                    {
                        borderFactory.SetValue(Border.BorderThicknessProperty, new Thickness(0, 1, 0, 0));
                    }
                    else if (GetVerticalLines(gridView))
                    {
                        borderFactory.SetValue(Border.BorderThicknessProperty, new Thickness(1, 0, 0, 0));
                    }


                    borderFactory.SetValue(Border.BorderBrushProperty, System.Windows.Media.Brushes.Black);


                    //Border b;
                    //b.Margin
                    FrameworkElementFactory TextblockFactory = new FrameworkElementFactory(typeof(TextBlock));
                    TextblockFactory.SetBinding(TextBlock.TextProperty, new Binding(COLS[i].DisplayMember));
                    TextblockFactory.SetValue(TextBlock.MarginProperty, new Thickness(6, 2, 6, 2));

                    TextblockFactory.SetValue(TextBlock.TextAlignmentProperty, COLS[i].align);
                    TextblockFactory.SetValue(TextBlock.ToolTipProperty, COLS[i].align.ToString());
                    borderFactory.AppendChild(TextblockFactory);
                    d.VisualTree = borderFactory;
                }

                column.CellTemplate = d;
                column.Width        = COLS[i].width;

                gridView.Columns.Add(column);
            }
        }