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; }
// apply the new color scheme to the grid static void OnColorSchemeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var grid = (C1FlexGridBook)d; ColorSchemeManager.ApplyColorScheme(grid, grid.ColorScheme); }