gpt4 book ai didi

wpf - 使用带有 mvvm 的扩展 Toolkit Richtext 框来绑定(bind)彩色文本

转载 作者:行者123 更新时间:2023-12-03 10:49:44 25 4
gpt4 key购买 nike

我有一个看起来像这样的类:

public class Line
{
public Color Color { get; set; }
public string Text { get; set; }
}

我正在使用 mvvm,现在我有一个字符串属性,我将 Text 绑定(bind)到,我的 xaml 看起来像这样
<toolkit:RichTextBox Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}" TextOptions.TextFormattingMode="Ideal" TextOptions.TextRenderingMode="Aliased" AcceptsTab="True" AcceptsReturn="True"/>

我最初使用列表框进行了此设置,并且能够轻松转换我的颜色,但是我看不到如何使用 rtb 执行此操作。我唯一能想到的顶部是在更新我的属性之前将 rtf 格式添加到字符串中。我猜有一个更简单的解决方案吗?

最佳答案

不确定工具包 RTB 是否支持此功能,但如果您还没有尝试过,您可以查看是否设置 TextElement.Foreground作品:

<RichTextBox ...>
<TextElement.Foreground>
<SolidColorBrush Color="{Binding Color}" />
</TextElement.Foreground>

关于wpf - 使用带有 mvvm 的扩展 Toolkit Richtext 框来绑定(bind)彩色文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9316139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com