public static void AddRange(this GridViewColumnCollection collection, IEnumerable <GridViewColumn> columns)
 {
     foreach (var gridViewColumn in columns)
     {
         collection.Add(gridViewColumn);
     }
 }
Ejemplo n.º 2
0
        protected void ReloadFiles()
        {
            _colors.Clear();
            ISet <string> colors = new HashSet <string>();

            foreach (string color in _colorResourceFiles.SelectMany(crd => crd.Colors.Keys))
            {
                colors.Add(color);
            }
            int index = 0;

            foreach (string color in colors.OrderBy(c => c))
            {
                _colors.Add(new ColorRow(this, color, index++));
            }
            GridViewColumnCollection gvcc = ((GridView)ColorsList.View).Columns;

            for (int i = gvcc.Count; i > _colorResourceFiles.Count + 1; i--)
            {
                gvcc.RemoveAt(i - 1);
            }
            for (int i = gvcc.Count; i < _colorResourceFiles.Count + 1; i++)
            {
                DataTemplate colorTemplate = ColorsList.FindResource("ColorTemplate" + (i - 1)) as DataTemplate;
                gvcc.Add(new GridViewColumn
                {
                    Width        = 150,
                    Header       = _colorResourceFiles[i - 1].ThemeName,
                    CellTemplate = colorTemplate,
                });
            }
        }
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            string xaml = Settings.Default.SearchColumns;

            if (!String.IsNullOrEmpty(xaml))
            {
                //listView1.View = XamlReader.Parse(xaml) as GridView;

                var savedCols = XamlReader.Parse(xaml) as GridViewColumnCollection;

                GridViewColumnCollection cols = ((GridView)listView1.View).Columns;

                var theCols = new List <GridViewColumn>();

                foreach (GridViewColumn col in savedCols)
                {
                    theCols.Add(col);
                }

                cols.Clear();
                savedCols.Clear();

                foreach (GridViewColumn col in theCols)
                {
                    col.HeaderTemplate = listView1.TryFindResource("HeaderTemplateSortNon") as DataTemplate;
                    cols.Add(col);
                }
            }

            AddSortBinding();
        }
Ejemplo n.º 4
0
        private void RefillColumns()
        {
            GridViewColumnCollection columns = (m_stackListView.View as GridView).Columns;

            columns.Clear();

            if (m_showDecimalMenu.IsChecked)
            {
                GridViewColumn column = new GridViewColumn();
                column.DisplayMemberBinding = new Binding("Value");
                column.Header = "Decimal";
                column.Width  = Double.NaN;
                columns.Add(column);
            }
            if (m_showHexadecimalMenu.IsChecked)
            {
                GridViewColumn column = new GridViewColumn();
                column.DisplayMemberBinding = new Binding("Hex");
                column.Header = "Hexadecimal";
                column.Width  = Double.NaN;
                columns.Add(column);
            }
            if (m_showBinaryMenu.IsChecked)
            {
                GridViewColumn column = new GridViewColumn();
                column.DisplayMemberBinding = new Binding("Binary");
                column.Header = "Binary";
                column.Width  = Double.NaN;
                columns.Add(column);
            }
            if (m_showExpressionMenu.IsChecked)
            {
                GridViewColumn column = new GridViewColumn();
                column.DisplayMemberBinding = new Binding("Expression");
                column.Header = "Expression";
                column.Width  = 150;
                columns.Add(column);
            }
        }
Ejemplo n.º 5
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var columns = value as IEnumerable <Column>;

            if (columns == null)
            {
                return(null);
            }

            var cols = new GridViewColumnCollection();

            foreach (var col in columns)
            {
                var gc = new GridViewColumn();

                gc.Header = col.Header;
                if (col.Type == ColumnType.Number || col.Type == ColumnType.RightAligned)
                {
                    gc.CellTemplate = getRightAlignDataTemplate(col.BindingExpression);
                }
                else
                {
                    var binding = new Binding(col.BindingExpression);
                    if (col.OneTimeBinding)
                    {
                        binding.Mode = BindingMode.OneTime;
                    }
                    gc.DisplayMemberBinding = binding;
                }

                if (col.Size == ColumnSize.FullWidth)
                {
                    //TODO: Hack
                    var width = Application.Current.MainWindow.Width - 60;
                    gc.Width = width;
                }
                else if (col.Size == ColumnSize.Auto)
                {
                    gc.Width = double.NaN;
                }

                if (col.Width.HasValue)
                {
                    gc.Width = col.Width.Value;
                }

                cols.Add(gc);
            }
            return(cols);
        }
Ejemplo n.º 6
0
 public static void AddColumn(ListView listView, GridViewColumnCollection columnCol, ColumnInfo[] colInfos)
 {
     foreach (var colInfo in colInfos)
     {
         if (columnCol.Any(c => c.Header.Equals(colInfo.Header))) //Prevent re-add.
         {
             break;
         }
         else
         {
             columnCol.Add(createColumn(listView, colInfo));
         }
     }
 }
        /// <summary>
        /// When the page is loaded, retrieve the persisted column layout
        /// This is a pretty grubby way of doing things but I couldn't think
        /// of anything better :/
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            //this event will fire not only when is first shown, but every time its shown
            // eg when switching between tabs.  Not sure why
            if (_loaded)
            {
                return;
            }

            //fetch the layout from settings
            string xaml = Properties.Settings.Default.SearchColumns;

            if (!String.IsNullOrEmpty(xaml))
            {
                GridViewColumnCollection savedCols    = XamlReader.Parse(xaml) as GridViewColumnCollection;
                GridViewColumnCollection gridViewCols = ((GridView)listView1.View).Columns;

                //we can't share GridViewColumns between collections, nor can we
                //remove one during a foreach, so we have to copy them to a list,
                //then add them to the collection.
                List <GridViewColumn> tempCols = new List <GridViewColumn>();

                foreach (GridViewColumn col in savedCols)
                {
                    tempCols.Add(col);
                }

                gridViewCols.Clear();
                savedCols.Clear();

                //TODO: we should be using the existing converter resource rather than making a new one
                BooleanToVisibilityConverter boolToVisCon = new BooleanToVisibilityConverter();

                foreach (GridViewColumn col in tempCols)
                {
                    //add the templates, bindings, and set the visible states as these aren't persisted
                    col.HeaderTemplate = listView1.TryFindResource("HeaderTemplateSortNon") as DataTemplate;
                    GridViewColumnHeader gvch = col.Header as GridViewColumnHeader;
                    MenuItem             mnu  = this.FindName("mnuCol" + gvch.Content.ToString()) as MenuItem;
                    mnu.IsChecked = (gvch.Visibility == System.Windows.Visibility.Visible);
                    Binding b = new Binding("IsChecked");
                    b.ElementName = "mnuCol" + gvch.Content.ToString();
                    b.Converter   = boolToVisCon;
                    gvch.SetBinding(UIElement.VisibilityProperty, b);
                    gridViewCols.Add(col);
                }
            }
            _loaded = true;
        }
Ejemplo n.º 8
0
        private GridViewBandColumn FindBandColumn(GridViewColumnCollection columns, DateTime currentDate, string caption)
        {
            GridViewBandColumn band = columns[caption] as GridViewBandColumn;

            if (band == null)
            {
                band = new GridViewBandColumn()
                {
                    Caption = caption
                };
                columns.Add(band);
            }

            return(band);
        }
Ejemplo n.º 9
0
        private void ResetOldFiltered()
        {
            while (_columns.Count > 0)
            {
                _filteredColumns.Add(_columns[0]);
                _columns.RemoveAt(0);
            }
            _filteredColumns.Sort(SortByPosition);

            foreach (var column in _filteredColumns)
            {
                _columns.Add(column);
            }
            _filteredColumns.Clear();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 配置GridView的列
        /// </summary>
        /// <param name="nameHeader">Name列模版</param>
        /// <param name="nameWidth">Name列宽度</param>
        /// <param name="listColumns">列集合</param>
        public void SetColumns(GridViewColumnHeader nameHeader, int nameWidth, List <GridViewColumn> listColumns)
        {
            GridViewColumnCollection gvcc    = (GridViewColumnCollection)mResouce["Gvcc"];
            GridViewColumn           gvcName = gvcc[0];

            gvcName.Header = nameHeader;
            gvcName.Width  = nameWidth;
            for (int i = gvcc.Count - 1; i > 0; i--)
            {
                gvcc.Remove(gvcc[i]);
            }
            for (int i = 0; i < listColumns.Count; i++)
            {
                gvcc.Add(listColumns[i]);
            }
        }
Ejemplo n.º 11
0
        public GridTree()
        {
            mResouce.Source = new Uri("VCCustomControls;component/TreeViews/Themes/GridTreeNameColumn.xaml", UriKind.Relative);
            Columns         = new GridViewColumnCollection();
            GridViewColumn nameColumn = new GridViewColumn();

            nameColumn.Header = "Name";
            DataTemplate dt = (DataTemplate)mResouce["CellTemplate_Name"];

            if (dt != null)
            {
                nameColumn.CellTemplate = dt;
            }
            else
            {
                nameColumn.DisplayMemberBinding = new Binding("Name");
            }
            Columns.Add(nameColumn);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Converts an array of <see cref="ColumnData"/> instances to <see cref="GridViewColumn"/> instances.
        /// </summary>
        /// <param name="value">The array of <see cref="ColumnData"/> instances</param>
        /// <param name="targetType">Not used</param>
        /// <param name="parameter">Not used</param>
        /// <param name="culture">Not used</param>
        /// <returns>An array of <see cref="GridViewColumn"/> instances</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var collection = new GridViewColumnCollection();

            if (value is IEnumerable <ColumnData> columns)
            {
                foreach (var c in columns)
                {
                    collection.Add(new GridViewColumn()
                    {
                        Header = c,
                        DisplayMemberBinding = new Binding(c.DisplayMember)
                        {
                            StringFormat = c.DisplayFormat
                        }
                    });
                }
            }

            return(collection);
        }
Ejemplo n.º 13
0
        private static void OnColumnHeandersChange(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            var newValue = e.NewValue as TreeListViewColumnCollection;
            var value    = newValue.FirstOrDefault();

            if (value is null)
            {
                return;
            }

            #region 模版生成

            #region toggle button

            var dockpanel = new FrameworkElementFactory(typeof(DockPanel));
            dockpanel.SetValue(DockPanel.LastChildFillProperty, true);

            var toggleButton = new FrameworkElementFactory(typeof(ToggleButton));
            toggleButton.Name = "Expander";
            toggleButton.SetValue(ToggleButton.ClickModeProperty, ClickMode.Press);

            Binding marginBinding   = new Binding();
            var     relativeSourece = new RelativeSource();
            relativeSourece.AncestorType = typeof(TreeListViewItem);
            marginBinding.RelativeSource = relativeSourece;
            marginBinding.Path           = new PropertyPath("Level");
            marginBinding.Converter      = new Converters.LevelToIndentConverter();
            toggleButton.SetBinding(ToggleButton.MarginProperty, marginBinding);

            var isCheckBinding = new Binding();
            isCheckBinding.RelativeSource = relativeSourece;
            isCheckBinding.Path           = new PropertyPath("IsExpanded");
            toggleButton.SetBinding(ToggleButton.IsCheckedProperty, isCheckBinding);

            Style expandCollapseToggleStyle = new Style();
            expandCollapseToggleStyle.Setters.Add(new Setter(ToggleButton.WidthProperty, 19.00));
            expandCollapseToggleStyle.Setters.Add(new Setter(ToggleButton.HeightProperty, 13.00));
            expandCollapseToggleStyle.Setters.Add(new Setter(ToggleButton.FocusableProperty, false));

            var toggleButtonTemplate = new ControlTemplate();

            #region the template style and trigger of the toggle button

            FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border));
            border.SetValue(Border.WidthProperty, 19.00);
            border.SetValue(Border.HeightProperty, 13.00);
            border.SetValue(Border.BackgroundProperty, Brushes.Transparent);
            var innerborder = new FrameworkElementFactory(typeof(Border));
            innerborder.SetValue(Border.WidthProperty, 9.00);
            innerborder.SetValue(Border.HeightProperty, 9.00);
            innerborder.SetValue(Border.BorderBrushProperty, new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF7898B5")));
            innerborder.SetValue(Border.BorderThicknessProperty, new Thickness(1));
            innerborder.SetValue(Border.CornerRadiusProperty, new CornerRadius(1));
            innerborder.SetValue(Border.SnapsToDevicePixelsProperty, true);

            var linearGradientBrush = new LinearGradientBrush();
            linearGradientBrush.StartPoint = new Point(0, 0);
            linearGradientBrush.EndPoint   = new Point(1, 1);
            var gradientStops = new GradientStopCollection();
            gradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FFFFFFFF"), 0.2));
            gradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FFC0B7A6"), 1));
            linearGradientBrush.GradientStops = gradientStops;
            innerborder.SetValue(Border.BackgroundProperty, linearGradientBrush);

            var path = new FrameworkElementFactory(typeof(Path));
            path.Name = "ExpandPath";
            path.SetValue(Path.NameProperty, "ExpandPath");
            path.SetValue(Path.MarginProperty, new Thickness(1));
            string sData = "M 0 2 L 0 3 L 2 3 L 2 5 L 3 5 L 3 3 L 5 3 L 5 2 L 3 2 L 3 0 L 2 0 L 2 2 Z";
            path.SetValue(Path.DataProperty, TypeDescriptor.GetConverter(typeof(Geometry)).ConvertFrom(sData) as Geometry);
            path.SetValue(Path.FillProperty, Brushes.Black);
            innerborder.AppendChild(path);
            border.AppendChild(innerborder);

            toggleButtonTemplate.VisualTree = border;

            Trigger isCheckedTrigger = new Trigger();
            isCheckedTrigger.Property = ToggleButton.IsCheckedProperty;
            isCheckedTrigger.Value    = true;
            var sTriggerData = "M 0 2 L 0 3 L 5 3 L 5 2 Z";
            isCheckedTrigger.Setters.Add(new Setter()
            {
                TargetName = "ExpandPath", Property = Path.DataProperty, Value = TypeDescriptor.GetConverter(typeof(Geometry)).ConvertFrom(sTriggerData) as Geometry
            });
            toggleButtonTemplate.Triggers.Add(isCheckedTrigger);

            #endregion the template style and trigger of the toggle button

            expandCollapseToggleStyle.Setters.Add(new Setter(ToggleButton.TemplateProperty, toggleButtonTemplate));

            toggleButton.SetValue(StyleProperty, expandCollapseToggleStyle);

            toggleButton.SetValue(DockPanel.DockProperty, Dock.Left);
            dockpanel.AppendChild(toggleButton);

            #endregion toggle button

            var block       = new FrameworkElementFactory(typeof(TextBlock));
            var textBinding = new Binding();
            textBinding.Path = new PropertyPath(value.Field);
            block.SetBinding(TextBlock.TextProperty, textBinding);
            block.SetBinding(TextBlock.ToolTipProperty, textBinding);
            block.SetValue(TextBlock.TextTrimmingProperty, TextTrimming.CharacterEllipsis);
            dockpanel.AppendChild(block);

            var dataTemplate = new DataTemplate {
                VisualTree = dockpanel,
            };

            var hiddenTrigger = new DataTrigger();

            Binding itemBinding = new Binding();
            itemBinding.Path           = new PropertyPath("HasItems");
            itemBinding.RelativeSource = relativeSourece;

            hiddenTrigger.Binding = itemBinding;
            hiddenTrigger.Value   = false;
            hiddenTrigger.Setters.Add(new Setter(ToggleButton.VisibilityProperty, Visibility.Hidden, "Expander"));

            dataTemplate.Triggers.Add(hiddenTrigger);

            #endregion 模版生成

            var columns = new GridViewColumnCollection();
            foreach (var item in newValue)
            {
                var col = new GridViewColumn()
                {
                    Header = item.Header,
                };
                if (item.Field == value.Field)
                {
                    col.CellTemplate = dataTemplate;
                    columns.Add(col);
                    continue;
                }
                col.DisplayMemberBinding = new Binding()
                {
                    Path = new PropertyPath(item.Field)
                };
                columns.Add(col);
            }

            (obj as TreeListView).Columns = columns;
        }
        /// <summary>
        /// The generated columns for grid.
        /// </summary>
        /// <returns>
        /// The <see cref="GridViewColumnCollection"/>.
        /// </returns>
        private GridViewColumnCollection GeneratedColumnsForGrid()
        {
            if (MembersTable == null)
            {
                return null;
            }
            var columns = new GridViewColumnCollection();
            var collection = new List<GridViewDataColumn>();

            DataTemplate ColumnCheckboxSelected = (DataTemplate)Application.Current.Resources["ColumnCheckboxSelected"];

            foreach (var dcolumn in MembersTable.Columns)
            {              
                var gridColumn = new GridViewDataColumn { Header = dcolumn.Header, UniqueName = dcolumn.ColumnName };
                DynamicColumn customColumn = GridColumns.FirstOrDefault(d => d.ColumnName == dcolumn.ColumnName);

                var path = gridColumn.DataMemberBinding.Path.Path;
                gridColumn.DataMemberBinding = new Binding
                {
                    Path = new PropertyPath(path),
                    Mode = BindingMode.TwoWay,
                };
                if (customColumn != null && customColumn.IsSelectedColumn && ColumnCheckboxSelected != null)
                {
                    gridColumn.CellTemplate = ColumnCheckboxSelected;
                }

                columns.Add(gridColumn);
            }
            return columns;
        }
 public CompareViewModel()
 {
     _targetDirectory = Settings.Default.LastCompareDirectory;
     _stringTranslationColumnCollection = new Lazy <GridViewColumnCollection>(() => {
         if (ApplicationModel == null)
         {
             throw new InvalidOperationException("Application model must be defined");
         }
         var gvcc = new GridViewColumnCollection {
             new GridViewColumn {
                 Header = "Key",
                 DisplayMemberBinding = new Binding("Item1"),
                 Width = 100
             }
         };
         var converter = new TranslatedValueConverter();
         var cultures  = GetSharedCultures();
         foreach (var culture in cultures)
         {
             gvcc.Add(new GridViewColumn()
             {
                 Header = new CultureInfo(culture).DisplayName,
                 DisplayMemberBinding = new Binding("Item2.Values")
                 {
                     Converter = converter, ConverterParameter = culture
                 }
             });
         }
         return(gvcc);
     });
     _stringTranslationTranslationColumnCollection = new Lazy <GridViewColumnCollection>(() => {
         if (ApplicationModel == null)
         {
             throw new InvalidOperationException("Application model must be defined");
         }
         var gvcc = new GridViewColumnCollection {
             new GridViewColumn {
                 Header = "Key",
                 DisplayMemberBinding = new Binding("Item1"),
                 Width = 100
             }
         };
         var converter = new TranslatedValueConverter();
         var cultures  = GetSharedCultures().ToList();
         foreach (var culture in cultures)
         {
             gvcc.Add(new GridViewColumn()
             {
                 Header = $"{new CultureInfo( culture ).DisplayName} (source)",
                 DisplayMemberBinding = new Binding("Item2.Values")
                 {
                     Converter = converter, ConverterParameter = culture
                 }
             });
         }
         foreach (var culture in cultures)
         {
             gvcc.Add(new GridViewColumn()
             {
                 Header = $"{new CultureInfo( culture ).DisplayName} (target)",
                 DisplayMemberBinding = new Binding("Item3.Values")
                 {
                     Converter = converter, ConverterParameter = culture
                 }
             });
         }
         return(gvcc);
     });
 }