I have a textBlock to which I’ve added some text e.g. as follows:
textBlock1.Inlines.Add(new Run("One "));
textBlock1.Inlines.Add(new Run("Two "));
textBlock1.Inlines.Add(new Run("Three "));
How can I add a click event that changes the color of the text of the inline that has been clicked?
e.g. if “One” is clicked I’d like it to have a red font; then if “Two” is clicked, I’d like “One” to be black again, and “Two” to be red, so that the color of the last word clicked is red.
I’m fairly new to programming with c# and wpf.
Thanks for your help
Something like this should do the trick
But you will have to handle click with “MouseDown” or “MouseUp” as Textblock does not have Click event
To color one at a certain index this is a quick example.
Usage:
Find position: