Jango
Jango

Reputation: 3

Wpf textblock partial background

I need to set a marker on a derived (inherited) textblock that will give the user an indication whether text is Left Right or Center justified. Derived class has a property called justification which is an enum with Left Right and Centre values. So I want to change background color of the textBlock partially i.e. if it is Left Justified then 25% of background on the left is a different color. Length of the string in the text block can vary and is not static.

Putting the textblock in another element e.g. border is not an option but I am open to any other suggestions that can manipulate Textblock without changing its size to visually mark justification.

Upvotes: 0

Views: 363

Answers (1)

Emond
Emond

Reputation: 50672

You could assign a LinearGradientBrush to the background and manipulate the colors and the offsets of the gradientstops.

Upvotes: 3

Related Questions