Creating a code snippet dynamically

SyntaxEditor for WPF Forum

Posted 1 year ago by Daisuke Nakada
Version: 17.2.0664
Avatar

Hi,

I want to create a code snippet object dynamically in code (instead of loading from a file), and insert the snippet on the editor.

Is this possible?

I read the documentations and the sample browser but could not find the example for doing that.

Thank you.

Comments (3)

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Yes, you can create an instance of the CodeSnippet class and fill in its members appropriately via code.  That is basically what happens when you load a code snippet file.

Then if you look at the "SyntaxEditor / User Interface Features / IntelliPrompt Features / Code Snippets" topic, the second section in there gives an example of programmatically creating a template session using a CodeSnippet instance.  That's what you would do to open it.


Actipro Software Support

Posted 1 year ago by Daisuke Nakada
Avatar

Thank you for your response. I tried it and it worked fine.

I have another question about the code snippet. I have weird highlightings between the current line and the code snippet.

When a snippet is inserted on my editor, the current line highlighting is canceled. And when I start editing one of the snippet fields, the current line highlighting appears and the code snippet highlightings are canceld instead. Then, when I press [Tab] key to move to other snippet field, the current line highlighting is canceled again and the code snippet highlightins appear.

This does not occur on your Sample Browser. So I think I'm doing something wrong but cannot find out what it is. Could you give me some advice on this, please?

Thank you.

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I tried to reproduce this in the Sample Browser too but was unable.  Did you change the style for the current line highlight, like perhaps adding a solid background?  Offhand I can't really think of anything else that would cause it.  If you can reproduce it in a new simple sample, that would be helpful.


Actipro Software Support

The latest build of this product (v2019.1 build 0684) was released 13 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.