protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
        {
            editor.EditorScrolled -= Editor_EditorScrolled;
            editor.CaretChangedByPointerClick -= Editor_CaretChangedByPointerClick;

            editor = null;
            editorViewModel = null;

            disposables.Dispose();
        }
        protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
        {
            editor = this.Find<TextEditor.TextEditor>("editor");

            editor.CaretChangedByPointerClick += Editor_CaretChangedByPointerClick;
            editor.EditorScrolled += Editor_EditorScrolled;

            editorViewModel = DataContext as EditorViewModel;

            if (editorViewModel != null && editor != null)
            {
                editorViewModel.Model.Editor = editor;
                editor.Focus();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Calls the <see cref="OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)"/> method
        /// for this control and all of its visual descendents.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
        {
            Logger.Verbose(LogArea.Visual, this, "Detached from visual tree");

            _visualRoot = null;

            if (RenderTransform != null)
            {
                RenderTransform.Changed -= RenderTransformChanged;
            }

            OnDetachedFromVisualTree(e);
            e.Root?.Renderer?.AddDirty(this);

            if (VisualChildren != null)
            {
                foreach (Visual child in VisualChildren.OfType <Visual>())
                {
                    child.OnDetachedFromVisualTreeCore(e);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Calls the <see cref="OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)"/> method
        /// for this control and all of its visual descendents.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs e)
        {
            Logger.Verbose(LogArea.Visual, this, "Attached to visual tree");

            _visualRoot = e.Root;

            if (RenderTransform != null)
            {
                RenderTransform.Changed += RenderTransformChanged;
            }

            OnAttachedToVisualTree(e);
            InvalidateVisual();

            if (VisualChildren != null)
            {
                foreach (Visual child in VisualChildren.OfType <Visual>())
                {
                    child.OnAttachedToVisualTreeCore(e);
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// Called when the control is removed from a visual tree.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
 {
 }
Beispiel #6
0
 /// <summary>
 /// Called when the control is added to a visual tree.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
 {
 }
Beispiel #7
0
 /// <summary>
 /// Called when the control is removed from a visual tree.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
 {
     DetachedFromVisualTree?.Invoke(this, e);
 }
Beispiel #8
0
 /// <summary>
 /// Called when the control is added to a visual tree.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
 {
     AttachedToVisualTree?.Invoke(this, e);
 }
Beispiel #9
0
        /// <summary>
        /// Sets the visual parent of the Visual.
        /// </summary>
        /// <param name="value">The visual parent.</param>
        private void SetVisualParent(Visual value)
        {
            if (_visualParent == value)
            {
                return;
            }
            
            var old = _visualParent;
            _visualParent = value;

            if (VisualRoot != null)
            {
                var e = new VisualTreeAttachmentEventArgs(VisualRoot);
                OnDetachedFromVisualTreeCore(e);
            }

            if (_visualParent is IRenderRoot || _visualParent?.IsAttachedToVisualTree == true)
            {
                var root = this.GetVisualAncestors().OfType<IRenderRoot>().FirstOrDefault();
                var e = new VisualTreeAttachmentEventArgs(root);
                OnAttachedToVisualTreeCore(e);
            }

            OnVisualParentChanged(old, value);
        }
Beispiel #10
0
 /// <summary>
 /// Called when the control is removed from a visual tree.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
 {
     DetachedFromVisualTree?.Invoke(this, e);
 }
Beispiel #11
0
 /// <summary>
 /// Called when the control is added to a visual tree.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
 {
     AttachedToVisualTree?.Invoke(this, e);
 }
Beispiel #12
0
        /// <summary>
        /// Calls the <see cref="OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)"/> method 
        /// for this control and all of its visual descendents.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
        {
            Logger.Verbose(LogArea.Visual, this, "Detached from visual tree");

            VisualRoot = null;

            if (RenderTransform != null)
            {
                RenderTransform.Changed -= RenderTransformChanged;
            }

            OnDetachedFromVisualTree(e);

            if (VisualChildren != null)
            {
                foreach (Visual child in VisualChildren.OfType<Visual>())
                {
                    child.OnDetachedFromVisualTreeCore(e);
                }
            }
        }
Beispiel #13
0
        protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
        {
            var canScrollHorizontally = this.GetObservable(AcceptsReturnProperty)
                .Select(x => !x);


            var horizontalScrollBarVisibility = this.GetObservable(AcceptsReturnProperty)
                .Select(x => x ? ScrollBarVisibility.Auto : ScrollBarVisibility.Hidden);

            disposables.Add(Bind(
                ScrollViewer.HorizontalScrollBarVisibilityProperty,
                horizontalScrollBarVisibility,
                BindingPriority.Style));

            disposables.Add(TextDocumentProperty.Changed.Subscribe(_ => { SelectionStart = SelectionEnd = CaretIndex = -1; }));

            disposables.Add(this.GetObservable(OffsetProperty).Subscribe(_ =>
            {
                EditorScrolled?.Invoke(this, new EventArgs());
            }));

            disposables.Add(AddHandler(KeyDownEvent, OnKeyDown, RoutingStrategies.Bubble));            
        }
Beispiel #14
0
 protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
 {
     TextView = null;
     TextDocument = null;
     disposables.Dispose();
 }