How to add a watermark-Text like "evaluation"?

SyntaxEditor for Silverlight Forum

Posted 8 years ago by Christel
Avatar
Again me - working very intensive now with the SyntaxEditor
How can I add in the SyntaxEditor control itself a watermark like it is presented, when the SyntaxEditor is not licensed?
(Now I have a license)
Thanks!
Christel

Comments (8)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Christel,

Check out our adornments samples. Our adornment layer functionality lets you insert any sort of layer in the editor. Layers can include any Silverlight UI elements, so a watermark would certainly be easy to do with that.


Actipro Software Support

Posted 8 years ago by Christel
Avatar
Sorry, it seems I'm fighting with simple problems, but I need help.
I tried it with the adornment layer.
But I don't know, which event I should use to add the watermark.
the view.TextAreaLayout gives me only access to the region, where the tex line is written. and it was called on each new line event.
But I want the watermark just shown once like the evaluation watermark.
I tried it with the Event view.SyntaxEditor.Loaded to make sure, the watermark is loaded only once.
But how can I center the watermark in the SyntaxEditor-View?
The IEditorView again gives me only the region, where the text is written, but not the whole window control.
Here is the code snippte of my WatermarkAdornmentManager. For the test case I just use a rectangle as watermark. As sson as it is positioned where I expect, I'll replace it by an image or text.
Could you please help me how to find the correct event and way to position the watermakr in the center of the editor-windowControl?
Perhaps I can even get an example code for the "evaluation" watermark shown in the syntax editor?

public WatermarkAdornmentManager(IEditorView view) : base(view, layerDefinition, true)
{
view.SyntaxEditor.Loaded += new RoutedEventHandler(SyntaxEditor_Loaded);
//view.TextAreaLayout += new EventHandler<TextViewTextAreaLayoutEventArgs>(view_TextAreaLayout);
}

void view_TextAreaLayout(object sender, TextViewTextAreaLayoutEventArgs e)
{
IEditorView editorView = sender as IEditorView;
AddAdornment(editorView);
}

void SyntaxEditor_Loaded(object sender, RoutedEventArgs e)
{
IEditorView editorView = sender as IEditorView;
AddAdornment(editorView);
}

private void AddAdornment(IEditorView activeView)
{
// Create a watermark textbox
SolidColorBrush brush = new SolidColorBrush(Color.FromArgb(0xFF, 0xF0, 0xF0, 0xF0));

// Create the adornment
Rectangle element = new Rectangle();
element.Width = 1000;
element.Height = 20;
element.Fill = brush;

// Add the adornment to the layer
//this.AdornmentLayer.AddAdornment(element, new
// Point(activeView.TextAreaViewportBounds.Width/2,
// activeView.TextAreaViewportBounds.Height/2), null, null);
this.AdornmentLayer.AddAdornment(element,
activeView.VisualElement.RenderTransformOrigin, null, null);
}

Thanks again for your help!
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

Instead of creating the adornment each time the TextAreaLayout event occurs, it would be better to create it once and set it to move as needed. You can store a reference to the IAdornment that is returned by AddAdornment.

The movement can be handled in the TextAreaLayout event. The TextViewTextAreaLayoutEventArgs.View property will provide you with a reference to the view. The IAdornment object that you stored a reference to has a Location property that you can set to move the adornment.

Adornments are over the “text area” portion of the view only.

Please let us know if you have further questions.


Actipro Software Support

Posted 8 years ago by Christel
Avatar
Thanks for the help!

What does that mean exactly:
"Adornments are over the “text area” portion of the view only."
Does it mean:
I can only see something in combination of one text line or one word?

I'm looking for a solution to add a watermark text in the editorview, even if no text is still seen or available.
This watermark will be overwritten when the user edits text.
It should look like the "evalution" string in the right corner of an evalution version of syntax editor.
It should look like this: _EDITORNAME_ is the watermark in the background.
The frame should mark the syntax editor control

--------------------------------------
|text text text text text
|text text text
| _EDITORNAME_(in the background as watermark)
|
|
---------------------------------------
Can I reach this with adornments?
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

The "text area" portion of the view refers to the portion of the view that text is able to be entered, not just the area where the caret is at the time or where text has already been entered. This excludes the margins, for example.

The view.TextAreaViewportBounds property holds a Rect that defines the boundaries of the text area portion of the view. You can use this Rect as a basis for positioning your watermark. For example, you could take the center point of the bounds and align int with the center point of your adornment, and it would then be centered in the text area of the view.

Please let us know if you have further questions.


Actipro Software Support

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

The next build of Silverlight Studio will include a new QuickStart that demonstrates this.


Actipro Software Support

Posted 8 years ago by Christel
Avatar
Hi,
when will the next build of Silverlight Studio be available?
I really appreciate this quickstart samples and also your help I got from you!!!
Great work!
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We're not sure yet when the next build of Silverlight Studio will be as we're still collecting updates for it.

If you email our support address, we can send you the source code for the new QuickStart.


Actipro Software Support

The latest build of this product (v2018.1 build 0232) was released 9 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.