/// <summary> /// The on apply template. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); this.grid = this.Template.FindName(PART_Grid, this) as Grid; this.sheetScroller = this.Template.FindName(PART_SheetScroller, this) as ScrollViewer; this.sheetGrid = this.Template.FindName(PART_SheetGrid, this) as Grid; this.columnScroller = this.Template.FindName(PART_ColumnScroller, this) as ScrollViewer; this.columnGrid = this.Template.FindName(PART_ColumnGrid, this) as Grid; this.rowScroller = this.Template.FindName(PART_RowScroller, this) as ScrollViewer; this.rowGrid = this.Template.FindName(PART_RowGrid, this) as Grid; this.rowSelectionBackground = this.Template.FindName(PART_RowSelectionBackground, this) as Border; this.columnSelectionBackground = this.Template.FindName(PART_ColumnSelectionBackground, this) as Border; this.selectionBackground = this.Template.FindName(PART_SelectionBackground, this) as Border; this.currentBackground = this.Template.FindName(PART_CurrentBackground, this) as Border; this.selection = this.Template.FindName(PART_Selection, this) as Border; this.autoFillSelection = this.Template.FindName(PART_AutoFillSelection, this) as Border; this.autoFillBox = this.Template.FindName(PART_AutoFillBox, this) as Border; this.topleft = this.Template.FindName(PART_TopLeft, this) as Border; this.textEditor = this.Template.FindName(PART_TextEditor, this) as TextBox; this.enumEditor = this.Template.FindName(PART_EnumEditor, this) as ComboBox; this.contentEditor = new ContentControl(); this.contentEditor.PreviewKeyDown += this.TextEditorPreviewKeyDown; this.enumEditor.SelectionChanged += this.EnumEditorSelectionChanged; this.textEditor.PreviewKeyDown += this.TextEditorPreviewKeyDown; this.textEditor.LostFocus += this.TextEditorLostFocus; this.sheetScroller.ScrollChanged += this.ScrollViewerScrollChanged; this.rowScroller.ScrollChanged += this.RowScrollerChanged; this.columnScroller.ScrollChanged += this.ColumnScrollerChanged; this.sheetScroller.SizeChanged += this.ScrollViewerSizeChanged; this.topleft.MouseLeftButtonDown += this.TopleftMouseLeftButtonDown; this.autoFillBox.MouseLeftButtonDown += this.AutoFillBoxMouseLeftButtonDown; this.columnGrid.MouseLeftButtonDown += this.ColumnGridMouseLeftButtonDown; this.columnGrid.MouseMove += this.ColumnGridMouseMove; this.columnGrid.MouseLeftButtonUp += this.ColumnGridMouseLeftButtonUp; this.rowGrid.MouseLeftButtonDown += this.RowGridMouseLeftButtonDown; this.rowGrid.MouseMove += this.RowGridMouseMove; this.rowGrid.MouseLeftButtonUp += this.RowGridMouseLeftButtonUp; this.columnGrid.Loaded += this.ColumnGridLoaded; this.sheetGrid.SizeChanged += this.ColumnGridSizeChanged; this.autoFiller = new AutoFiller(this.GetCellValue, this.TrySetCellValue); this.autoFillToolTip = new ToolTip { Placement = PlacementMode.Bottom, PlacementTarget = this.autoFillSelection }; this.UpdateGridContent(); this.OnSelectedCellsChanged(); this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, this.CopyExecute)); this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, this.CutExecute)); this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, this.PasteExecute)); this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, this.DeleteExecute)); }
/// <summary> /// When overridden in a derived class, is invoked whenever application code or internal processes call <see /// cref="M:System.Windows.FrameworkElement.ApplyTemplate" /> . /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); this.sheetScrollViewer = this.Template.FindName(PartSheetScrollViewer, this) as ScrollViewer; this.sheetGrid = this.Template.FindName(PartSheetGrid, this) as Grid; this.columnScrollViewer = this.Template.FindName(PartColumnScrollViewer, this) as ScrollViewer; this.columnGrid = this.Template.FindName(PartColumnGrid, this) as Grid; this.rowScrollViewer = this.Template.FindName(PartRowScrollViewer, this) as ScrollViewer; this.rowGrid = this.Template.FindName(PartRowGrid, this) as Grid; this.rowSelectionBackground = this.Template.FindName(PartRowSelectionBackground, this) as Border; this.columnSelectionBackground = this.Template.FindName(PartColumnSelectionBackground, this) as Border; this.selectionBackground = this.Template.FindName(PartSelectionBackground, this) as Border; this.currentBackground = this.Template.FindName(PartCurrentBackground, this) as Border; this.selection = this.Template.FindName(PartSelection, this) as Border; this.autoFillSelection = this.Template.FindName(PartAutoFillSelection, this) as Border; this.autoFillBox = this.Template.FindName(PartAutoFillBox, this) as Border; this.topLeft = this.Template.FindName(PartTopLeft, this) as Border; if (this.sheetScrollViewer == null) { throw new Exception(PartSheetScrollViewer + " not found."); } if (this.rowScrollViewer == null) { throw new Exception(PartRowScrollViewer + " not found."); } if (this.columnScrollViewer == null) { throw new Exception(PartColumnScrollViewer + " not found."); } if (this.topLeft == null) { throw new Exception(PartTopLeft + " not found."); } if (this.autoFillBox == null) { throw new Exception(PartAutoFillBox + " not found."); } if (this.columnGrid == null) { throw new Exception(PartColumnGrid + " not found."); } if (this.rowGrid == null) { throw new Exception(PartRowGrid + " not found."); } if (this.sheetGrid == null) { throw new Exception(PartSheetGrid + " not found."); } this.sheetScrollViewer.ScrollChanged += this.ScrollViewerScrollChanged; this.rowScrollViewer.ScrollChanged += this.RowScrollViewerScrollChanged; this.columnScrollViewer.ScrollChanged += this.ColumnScrollViewerScrollChanged; this.topLeft.MouseLeftButtonDown += this.TopLeftMouseLeftButtonDown; this.autoFillBox.MouseLeftButtonDown += this.AutoFillBoxMouseLeftButtonDown; this.columnGrid.MouseLeftButtonDown += this.ColumnGridMouseLeftButtonDown; this.columnGrid.MouseMove += this.ColumnGridMouseMove; this.columnGrid.MouseLeftButtonUp += this.ColumnGridMouseLeftButtonUp; this.rowGrid.MouseLeftButtonDown += this.RowGridMouseLeftButtonDown; this.rowGrid.MouseMove += this.RowGridMouseMove; this.rowGrid.MouseLeftButtonUp += this.RowGridMouseLeftButtonUp; this.columnGrid.Loaded += this.ColumnGridLoaded; this.sheetScrollViewer.SizeChanged += this.ColumnGridSizeChanged; this.sheetGrid.MouseLeftButtonDown += this.SheetGridMouseLeftButtonDown; this.autoFiller = new AutoFiller(this.GetCellValue, this.TrySetCellValue); this.autoFillToolTip = new ToolTip { Placement = PlacementMode.Bottom, PlacementTarget = this.autoFillSelection }; this.UpdateGridContent(); this.SelectedCellsChanged(); this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, (s, e) => this.Copy())); this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, (s, e) => this.Cut())); this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, (s, e) => this.Paste())); this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, (s, e) => this.Delete())); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); sheetScroller = Template.FindName(PART_SheetScroller, this) as ScrollViewer; sheetGrid = Template.FindName(PART_SheetGrid, this) as Grid; columnScroller = Template.FindName(PART_ColumnScroller, this) as ScrollViewer; columnGrid = Template.FindName(PART_ColumnGrid, this) as Grid; rowScroller = Template.FindName(PART_RowScroller, this) as ScrollViewer; rowGrid = Template.FindName(PART_RowGrid, this) as Grid; rowSelectionBackground = Template.FindName(PART_RowSelectionBackground, this) as Border; columnSelectionBackground = Template.FindName(PART_ColumnSelectionBackground, this) as Border; selectionBackground = Template.FindName(PART_SelectionBackground, this) as Border; currentBackground = Template.FindName(PART_CurrentBackground, this) as Border; selection = Template.FindName(PART_Selection, this) as Border; autoFillSelection = Template.FindName(PART_AutoFillSelection, this) as Border; autoFillBox = Template.FindName(PART_AutoFillBox, this) as Border; topleft = Template.FindName(PART_TopLeft, this) as Border; textEditor = Template.FindName(PART_TextEditor, this) as TextBox; enumEditor = Template.FindName(PART_EnumEditor, this) as ComboBox; contentEditor = new ContentControl(); enumEditor.SelectionChanged += EnumEditorSelectionChanged; textEditor.PreviewKeyDown += TextEditorPreviewKeyDown; textEditor.LostFocus += TextEditorLostFocus; sheetScroller.ScrollChanged += ScrollViewerScrollChanged; rowScroller.ScrollChanged += RowScrollerChanged; columnScroller.ScrollChanged += ColumnScrollerChanged; sheetScroller.SizeChanged += ScrollViewerSizeChanged; topleft.MouseLeftButtonDown += TopleftMouseLeftButtonDown; autoFillBox.MouseLeftButtonDown += AutoFillBoxMouseLeftButtonDown; columnGrid.MouseLeftButtonDown += ColumnGridMouseLeftButtonDown; columnGrid.MouseMove += ColumnGridMouseMove; columnGrid.MouseLeftButtonUp += ColumnGridMouseLeftButtonUp; columnGrid.Loaded += ColumnGridLoaded; sheetGrid.SizeChanged += ColumnGridSizeChanged; rowGrid.MouseLeftButtonDown += RowGridMouseLeftButtonDown; rowGrid.MouseMove += RowGridMouseMove; rowGrid.MouseLeftButtonUp += RowGridMouseLeftButtonUp; Focusable = true; autoFiller = new AutoFiller(GetCellValue, TrySetCellValue); autoFillToolTip = new ToolTip { Placement = PlacementMode.Bottom, PlacementTarget = autoFillSelection }; UpdateGridContent(); OnSelectedCellsChanged(); BuildContextMenus(); CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, CopyExecute)); CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, CutExecute)); CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, PasteExecute)); CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, DeleteExecute)); }