/// <summary> /// Called when an internal process or application calls <see cref="M:System.Windows.FrameworkElement.ApplyTemplate"/>, which is used to build the current template's visual tree. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); _editorArea.LayoutChanged += new EventHandler <TextAreaLayoutChangedEventArgs>(EditorLayoutChanged); _editorArea.ViewportHorizontalOffsetChanged += new EventHandler(EditorLayoutChanged); _editorArea.ViewportWidthChanged += new EventHandler(EditorLayoutChanged); _horizontalScrollBar = Template.FindName("PART_HorizontalScrollBar", this) as ScrollBar; _outerGrid = GetTemplateChild("PART_OuterGrid") as Grid; _splitButton = GetTemplateChild("PART_SplitButton") as IInputElement; _verticalScrollBar = GetTemplateChild("PART_VerticalScrollBar") as EditorScrollBar; ColumnDefinition gutterColumn = GetTemplateChild("_gutterColumn") as ColumnDefinition; ColumnDefinition contentColumn = GetTemplateChild("_contentColumn") as ColumnDefinition; RowDefinition contentRow = GetTemplateChild("_contentRow") as RowDefinition; _gutterColumnIndex = OuterGrid.ColumnDefinitions.IndexOf(gutterColumn); _contentColumnIndex = OuterGrid.ColumnDefinitions.IndexOf(contentColumn); _contentRowIndex = OuterGrid.RowDefinitions.IndexOf(contentRow); _canInsertGutter = _gutterColumnIndex > -1 && _contentRowIndex > -1; _canInsertEditorArea = _contentColumnIndex > -1 && _contentRowIndex > -1; if (_canInsertEditorArea) { _editorArea.VisualElement.SetValue(Grid.RowProperty, ContentRowIndex); _editorArea.VisualElement.SetValue(Grid.ColumnProperty, ContentColumnIndex); OuterGrid.Children.Add(_editorArea.VisualElement); } VerticalScrollBar.LeftShiftClick += new EventHandler <RoutedPropertyChangedEventArgs <Double> >(this.OnVerticalLeftShiftClick); VerticalScrollBar.Scroll += new ScrollEventHandler(this.VerticalScrollBarScrolled); HorizontalScrollBar.Minimum = VerticalScrollBar.Minimum = 0; HorizontalScrollBar.ValueChanged += new RoutedPropertyChangedEventHandler <Double>(this.OnHorizontalValueChanged); IsLineNumberGutterVisible = true; Dispatcher.BeginInvoke( DispatcherPriority.Render , new DispatcherOperationCallback( delegate { _editorArea.VisualElement.Focus(); return(null); } ) , null ); SizeChanged += new SizeChangedEventHandler(OnSizeChanged); }
/// <summary> /// Called when an internal process or application calls <see cref="M:System.Windows.FrameworkElement.ApplyTemplate"/>, which is used to build the current template's visual tree. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); _editorArea.LayoutChanged += new EventHandler<TextAreaLayoutChangedEventArgs>(EditorLayoutChanged); _editorArea.ViewportHorizontalOffsetChanged += new EventHandler(EditorLayoutChanged); _editorArea.ViewportWidthChanged += new EventHandler(EditorLayoutChanged); _horizontalScrollBar = Template.FindName("PART_HorizontalScrollBar", this) as ScrollBar; _outerGrid = GetTemplateChild("PART_OuterGrid") as Grid; _splitButton = GetTemplateChild("PART_SplitButton") as IInputElement; _verticalScrollBar = GetTemplateChild("PART_VerticalScrollBar") as EditorScrollBar; ColumnDefinition gutterColumn = GetTemplateChild("_gutterColumn") as ColumnDefinition; ColumnDefinition contentColumn = GetTemplateChild("_contentColumn") as ColumnDefinition; RowDefinition contentRow = GetTemplateChild("_contentRow") as RowDefinition; _gutterColumnIndex = OuterGrid.ColumnDefinitions.IndexOf(gutterColumn); _contentColumnIndex = OuterGrid.ColumnDefinitions.IndexOf(contentColumn); _contentRowIndex = OuterGrid.RowDefinitions.IndexOf(contentRow); _canInsertGutter = _gutterColumnIndex > -1 && _contentRowIndex > -1; _canInsertEditorArea = _contentColumnIndex > -1 && _contentRowIndex > -1; if (_canInsertEditorArea) { _editorArea.VisualElement.SetValue(Grid.RowProperty, ContentRowIndex); _editorArea.VisualElement.SetValue(Grid.ColumnProperty, ContentColumnIndex); OuterGrid.Children.Add(_editorArea.VisualElement); } VerticalScrollBar.LeftShiftClick += new EventHandler<RoutedPropertyChangedEventArgs<Double>>(this.OnVerticalLeftShiftClick); VerticalScrollBar.Scroll += new ScrollEventHandler(this.VerticalScrollBarScrolled); HorizontalScrollBar.Minimum = VerticalScrollBar.Minimum = 0; HorizontalScrollBar.ValueChanged += new RoutedPropertyChangedEventHandler<Double>(this.OnHorizontalValueChanged); IsLineNumberGutterVisible = true; Dispatcher.BeginInvoke( DispatcherPriority.Render , new DispatcherOperationCallback( delegate { _editorArea.VisualElement.Focus(); return null; } ) , null ); SizeChanged += new SizeChangedEventHandler(OnSizeChanged); }