
Hi,
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:And in codebehind:
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"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"
xmlns:syntaxEditor="http://schemas.actiprosoftware.com/winfx/xaml/syntaxeditor"
Title="MainWindow" Height="350" Width="525">
<Grid>
<docking:DockSite WindowActivated="DockSite_WindowActivated">
<docking:SplitContainer>
<docking:Workspace>
<docking:TabbedMdiHost x:Name="tabbedMdiHost">
<docking:TabbedMdiContainer>
<docking:DockingWindow>
<syntaxEditor:SyntaxEditor x:Name="e1" />
</docking:DockingWindow>
<docking:DockingWindow>
<syntaxEditor:SyntaxEditor x:Name="e2" />
</docking:DockingWindow>
</docking:TabbedMdiContainer>
</docking:TabbedMdiHost>
</docking:Workspace>
</docking:SplitContainer>
</docking:DockSite>
</Grid>
</Window>
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()
{
InitializeComponent();
}
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);
editor.Focus();
}
}
public static class Test
{
public static T FindChild<T>(this DependencyObject current) where T : DependencyObject
{
do
{
if (current is T)
{
return (T)current;
}
current = VisualTreeHelper.GetChild(current, 0);
}
while (current != null);
return null;
}
}
}