public override void OnApplyTemplate()
        {
            // allow base
            base.OnApplyTemplate();

            // get our parts
            _tabHolder = GetTemplateChild("_tabHolder") as Grid;
            _splitter = GetTemplateChild("_splitter") as GridSplitter;
            _sbHorz = GetTemplateChild("_sbH") as ScrollBar;
            _tabs = GetTemplateChild("_tabs") as C1TabControl;
            _sheets = new SheetCollection(this);

            _btnFirst = GetTemplateChild("_btnFirstSheet") as Button;
            _btnPrev = GetTemplateChild("_btnPreviousSheet") as Button;
            _btnNext = GetTemplateChild("_btnNextSheet") as Button;
            _btnLast = GetTemplateChild("_btnLastSheet") as Button;

            // add images to tab browsing buttons
            _btnFirst.Content = GetImage("FirstSheet.png");
            _btnPrev.Content = GetImage("PreviousSheet.png");
            _btnNext.Content = GetImage("NextSheet.png");
            _btnLast.Content = GetImage("LastSheet.png");

            // configure grid
            this.MergeManager = new ExcelMergeManager();
            this.CellFactory = new ExcelCellFactory(this);

            // apply default color scheme
            ColorSchemeManager.ApplyColorScheme(this, _defaultColorScheme);

            // hook up sheet navigation buttons
            _btnFirst.Click += (s, e) => { Sheets.SelectFirst(); };
            _btnPrev.Click += (s, e) => { Sheets.SelectPrev(); };
            _btnNext.Click += (s, e) => { Sheets.SelectNext(); };
            _btnLast.Click += (s, e) => { Sheets.SelectLast(); };

            // create undo/redo stack
            _undo = new ExcelUndoStack(this);
            _undo.StateChanged += (s, e) =>
            {
                SetValue(CanUndoProperty, _undo.CanUndo);
                SetValue(CanRedoProperty, _undo.CanRedo);
            };

            // enable column filtering
            _filter = new C1FlexGridFilter(this);
            _filter.UseCollectionView = true;
            _filter.Editor = new ExcelFilterEditor();

            // connect handlers to select columns and to insert references into formulas
            PreviewMouseLeftButtonDown += mouseLeftButtonDown;
            MouseLeftButtonUp += mouseLeftButtonUp;
            MouseMove += mouseMove;
            SelectionChanged += selectionChanged;
            LostMouseCapture += lostMouseCapture;
            CellEditEnded += cellEditEnded;

            // connect handler to resize selected columns
            ResizedColumn += resizedColumn;
        }
 public static void EnableFiltering(this C1FlexGrid flex, bool enable)
 {
     C1FlexGridFilter gridFilter = C1FlexGridFilterService.GetFlexGridFilter(flex);
     if (enable && gridFilter == null)
     {
         gridFilter = new C1FlexGridFilter();
         C1FlexGridFilterService.SetFlexGridFilter(flex, gridFilter);
         return;
     }
     if (!enable && gridFilter != null)
     {
         C1FlexGridFilterService.SetFlexGridFilter(flex, null);
     }
 }
Example #3
0
        private static void BindingColumnsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            try
            {
                var bindingColumns = e.NewValue as ObservableCollection <ColumnConfig>;
                if (bindingColumns != null)
                {
                    var c1FlexGrid = d as C1FlexGrid;
                    if (c1FlexGrid != null)
                    {
                        //List<string> list = new List<string>
                        //{
                        //    "Viewership",
                        //    "Sentiment",
                        //    "AssociationAvg",
                        //    "PreAwareness",
                        //    "PostAwarenessAvg"
                        //};

                        C1FlexGridFilter filter = new C1FlexGridFilter();

                        c1FlexGrid.Columns.Clear();
                        foreach (var bindingColumn in bindingColumns)
                        {
                            var column = new Column
                            {
                                Header              = bindingColumn.HeaderName,
                                Binding             = new Binding(bindingColumn.ColumnName),
                                Width               = new GridLength(bindingColumn.Width),
                                Format              = bindingColumn.FormatString,
                                ToolTip             = bindingColumn.HeaderDescription,
                                HorizontalAlignment = HorizontalAlignment.Left,
                                HeaderBackground    =
                                    new SolidColorBrush(ColorConverter.ConvertFromString(bindingColumn.HeaderColorString) is Color ? (Color)ColorConverter.ConvertFromString(bindingColumn.HeaderColorString) : Colors.White)
                            };
                            c1FlexGrid.Columns.Add(column);
                            //if(list.Contains(bindingColumn.ColumnName))
                            //{
                            //    filter.GetColumnFilter(column);
                            //    var cf13 = filter.GetColumnFilter(column);
                            //    cf13.FilterType = FilterType.Value;

                            //    filter.Apply();
                            //}
                        }

                        #region 设置双列头

                        //var ch = c1FlexGrid.ColumnHeaders;
                        //ch.Rows.Add(new Row());

                        //ch[0, 0] = "省份城市";
                        //ch[1, 0] = "省名";

                        //ch[0, 1] = "省份城市";
                        //ch[1, 1] = "城市";

                        //// allow merging the first fixed row
                        //ch.Rows[0].AllowMerging = true;

                        #endregion

                        //c1FlexGrid.AutoSizeColumns(0, c1FlexGrid.Columns.Count - 1, 0);

                        c1FlexGrid.CellFactory = new FlexGridCellFactory();

                        filter.Owner = c1FlexGrid;
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMessage.Show("列绑定出错");
                LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "Failed to BindingColumnsChanged", ex);
            }
            finally
            {
                if (LogHelper.LogLevel == LogLevelEnum.Debug || LogHelper.LogLevel == LogLevelEnum.Info)
                {
                    LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "BindingColumnsChanged", null);
                }
            }
        }