0
親愛的stackoverflow社區!文本框:混合顏色和數據綁定
我試圖找到解決我的問題,但我找不到任何。
問題:
我有一個綁定到一個串一個多行TextBox。每當我給字符串添加一些東西時,我想改變新部分的顏色,只有。
到底應該應該是這樣的:
(你的想法)
這是到目前爲止我的文本框:
<TextBox x:Name="ChatTextBox" Text="{Binding MyStringProperty , Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap"
AcceptsReturn="True"
IsReadOnly="True"></TextBox>
</ScrollViewer>
當搜索一個解決方案,我看到一些使用Inline的例子,但對我來說,Inline看起來不能動態。
<TextBlock TextWrapping="Wrap">
<TextBlock.Inlines>
<Run Foreground="Blue" Text="The first line in the Textbox is blue"/>
<Run Foreground="Green" Text="then I add this part and it is green"/>
<Run Foreground="Orange" Text="and this part is orange" />
</TextBlock.Inlines>
</TextBlock>
我不一定要綁定到一個字符串,如果需要任何其他對象(或目錄),這將不會是一個問題。
任何幫助,高度讚賞!先謝謝你。
謝謝您的回答。但據我所見,在這種情況下代碼仍然與3行的長度綁定。 如果我的文字長到10行怎麼辦? – Al0x