Manipulating Style Runs

The problem: I want to modify a StyleRun after it’s been added to StyledText.

The documentation is a little unclear about this. The page for the StyleRun.Text property indicates that the text property can be set, but it seems like it can only be set before it’s been added to a StyledText object. The StyledText page says that “If you want to operate on a StyleRun, you must remove the old run and replace it with the new run.

However, I’m running into issue when I try to remove an old run and replace it with a new one. I can add a new StyleRun to the end, but when I use StyledText.AddStyleRunAt, the program simply crashes without an error message.

The question: has anyone managed to successfully replace StyleRuns in a StyledText object?

Thank you all!

seems to work ok but then I’m using an older verion

[quote=495388:@Norman Palardy]seems to work ok but then I’m using an older verion[/quote]

Oh! Now that is interesting. Your sandbox project works for me.

I’ll have to see if I can track down what’s causing a crash on my end.

A StyledText object is basically just a wrapper around an array of StyleRuns. Maybe you should just convert your Styledtext into a StyleRun(), make the modifications you want and create a new Styledtext