This is a migrated thread and some comments may be shown as answers.

Setting a custom StyleDefinition on a span

1 Answer 77 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Fredrik Kvaal
Top achievements
Rank 1
Fredrik Kvaal asked on 13 Sep 2011, 10:18 AM
Hi.
We need to set/tag spans in the document with some custom data (of type string), so I've created a custom StylePropertyDefinition (e.g. like the Span.FontWeightProperty property, but our doesn't need to change the layout) and are trying to apply this to a span - but it doesn't seem to work.
Note: We serialize and deserialize the RadDocument ourselves - so I just need to be able to set this property runtime on a span and have that in memory until the document is deserialized.
Now I cant find any documentation or examples of doing this...
Is it possible to do something like this? 

Here's my prop definition:
public static readonly StylePropertyDefinition<string, Span, Paragraph> TextMetaInfoProperty =
new StylePropertyDefinition<string, Span, Paragraph>("TextMetaInfo", StylePropertyOptions.AffectsLayout, (s) => { return null; }, default(string));
(PS: Dont know what I should do in the "Selector" lambda - so I return null)

I'm trying to set the custom property like this:
span.DefaultStyleSettings.SetPropertyValue(TextMetaInfoProperty, metaInfo);

And read it like this:
var textMeta = span.DefaultStyleSettings.GetPropertyValue(TextMetaInfoProperty);

Any help would be very much appreciated!

1 Answer, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 16 Sep 2011, 05:21 PM
Hello Fredrik Kvaal,

The document is split into document elements (Spans included) with regard to the formatting of the text. Adding supplementary semantic information on these elements cannot be done.
If you need to keep some additional information in the document, you can use annotations - bookmarks or comments. More information on bookmarks for example can be found here, whereas some useful methods for programmatic use of comments can be viewed here.

Kind regards,
Iva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Fredrik Kvaal
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Share this question
or