Posted 18 years ago
by Willem Mitchell

What is the best practice for using the sytax editor in a WPF application. Using it as part of a Windows form or using the WindowsFormsHost control?
public class WPFSyntaxEditor : WindowsFormsHost
{
private SyntaxEditor _SyntaxEditor;
public WPFSyntaxEditor()
{
}
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
_SyntaxEditor = new SyntaxEditor();
this.Child = this.SyntaxEditor;
this.SyntaxEditor.SelectionChanged += new SelectionEventHandler(SyntaxEditor_SelectionChanged);
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut,ExecuteCutCommand ,CanExecuteCutCommand));
..... more command bindings
}
void SyntaxEditor_SelectionChanged(object sender, SelectionEventArgs e)
{
CommandManager.InvalidateRequerySuggested();
}
public SyntaxEditor SyntaxEditor
{
get
{
return _SyntaxEditor;
}
}
#region Cut
public void CanExecuteCutCommand(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = this.SyntaxEditor != null && this.SyntaxEditor.SelectedView.CanDelete;
e.Handled = true;
}
public void ExecuteCutCommand(object sender, ExecutedRoutedEventArgs e)
{
this.SyntaxEditor.SelectedView.CutToClipboard();
e.Handled = true;
this.SyntaxEditor.Focus();
}
#endregion
}
Please log in to a validated account to post comments.