使用扩展 Toolkit Richtext 框和 mvvm 绑定彩色文本
我有一个看起来像这样的类:
public class Line
{
public Color Color { get; set; }
public string Text { get; set; }
}
我正在使用 mvvm,现在我有一个将文本绑定到的字符串属性,我的 xaml 看起来像这样
<toolkit:RichTextBox Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}" TextOptions.TextFormattingMode="Ideal" TextOptions.TextRenderingMode="Aliased" AcceptsTab="True" AcceptsReturn="True"/>
我最初使用列表框设置了这个并且能够转换我的颜色没有太多麻烦,但是我不知道如何使用 rtb 来做到这一点。我唯一能想到的就是在更新我的属性之前将 rtf 格式添加到字符串中。我猜有一个更简单的解决方案吗?
I have a class that looks something like this:
public class Line
{
public Color Color { get; set; }
public string Text { get; set; }
}
I'm using mvvm and right now i'm have have a string properity that i bind Text to, my xaml looks like this
<toolkit:RichTextBox Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}" TextOptions.TextFormattingMode="Ideal" TextOptions.TextRenderingMode="Aliased" AcceptsTab="True" AcceptsReturn="True"/>
I originally had this set up with a list box and was able to Convert my color without to much trouble, however I'm failing to see how to do this with rtb. Only thing i can think of of the top is to add rtf formatting to the string prior to updating my property. I'm guessing there is a simpler solution though?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定工具包 RTB 是否支持此功能,但如果您还没有尝试过,您可以看看设置
TextElement.Foreground
是否有效:Not sure if the toolkit RTB supports this but if you did not try it yet you could see if setting
TextElement.Foreground
works: