Problem setting cursor in editor programmatically

SyntaxEditor for WPF Forum

Posted 13 years ago by Tino Schnerwitzki
Version: 11.1.0543

I´m using a SyntaxEditor inside a DockSite (or better its DocumentWindows). What I want to do is that as soon as I activate a DocumentWindow the cursor should be placed inside its SyntaxEditor.

The problem is that neither setting the Postion of the caret nor setting the selection and calling .Focus() on the Editor seem to work.

Any ideas what might be wrong?

Here is a simple sample:

<Window x:Class="WpfApplication2.MainWindow"
        Title="MainWindow" Height="350" Width="525">
        <docking:DockSite WindowActivated="DockSite_WindowActivated">
                    <docking:TabbedMdiHost x:Name="tabbedMdiHost">
                                <syntaxEditor:SyntaxEditor x:Name="e1" />
                                <syntaxEditor:SyntaxEditor x:Name="e2" />

And in codebehind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ActiproSoftware.Windows.Controls.Docking;
using ActiproSoftware.Windows.Controls.SyntaxEditor;
using ActiproSoftware.Text;

namespace WpfApplication2
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        public MainWindow()

        private void DockSite_WindowActivated(object sender, ActiproSoftware.Windows.Controls.Docking.DockingWindowEventArgs e)
            var editor = tabbedMdiHost.FindChild<SyntaxEditor>();
            editor.ActiveView.Selection.StartPosition = new TextPosition(0, 0);

    public static class Test
        public static T FindChild<T>(this DependencyObject current) where T : DependencyObject
                if (current is T)
                    return (T)current;
                current = VisualTreeHelper.GetChild(current, 0);
            while (current != null);
            return null;

Comments (1)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Tino,

You should not use the DockingWindow type directly like that. It is intended to only be used as a base class. You should use either a DocumentWindow or a ToolWindow in it's place.

Once you change that, it should properly move focus.

Actipro Software Support

The latest build of this product (v24.1.2) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.