Syntax editor and WPF

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by Willem Mitchell
Avatar
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?

Comments (2)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We have several customers using SyntaxEditor in WPF applications, inside WPF windows via the hosting. One customer who we talk with regularly even uses a SyntaxEditor in one of our RibbonWindow's that is part of our Ribbon product.


Actipro Software Support

Posted 13 years ago by Martin Wawrusch 2
Avatar
Do something like this:
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
    }
Works like a charm.

[Modified at 04/28/2007 09:08 AM]
The latest build of this product (v2020.1 build 0400) was released 5 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.