1

I have a TextBox control:

<TextBox Text={Binding MyText},.../>

where

MyText = "leftWord/rightWord";

I understand that to get multiple foreground colors I cannot use a TextBox but rather a TextBlock or RichTextBox. Since I need to edit the text, I will use a RichTextBox.

My goal is to highlight (change the foreground color) either "leftWord" or "rightWord" in the displayed text depending on the value of another property, such as

MyChoice = Left|Right

I am not sure how I can set the Run content to the right characters based on the MyChoice property. Is there a way I can pass the entire text to a converter, along with the value of MyChoice and somehow have that set the correct foreground colors? If so, I am not sure what the xaml would look like.

Would this be possible with a RichTextBox? I notice it has no Text property so I am not even sure how to bind (two-way binding) MyText to it.

4

1 回答 1

0

您可以使用 .substring(#,#); 创建 2 个变量;然后根据条件影响这些变量的前景色

于 2012-10-17T10:56:15.237 回答