【问题标题】:RichTextBox does not contain definition for almost everythingRichTextBox 不包含几乎所有内容的定义
【发布时间】:2016-08-12 03:01:43
【问题描述】:

所以今天我尝试使用丰富的文本框为我漂亮的控制台日志提供一种很酷的颜色。 但是代码有很多错误

    RichTextBox box = ConsoleTextBox;

    box.SelectionStart = box.TextLength;
    box.SelectionLength = 0;

    box.SelectionColor = color;
    box.AppendText(text);
    box.SelectionColor = box.ForeColor;

我在 SelectionStart、TextLength、SelectionLength、SlectionColor 和 ForeColor 上遇到错误。 错误说:

RichTextBox 不包含“上述之一”的定义,并且 没有扩展方法'上述之一'

这是我的 XAML:

<Grid>
    <RichTextBox Name="ConsoleTextBox"
                 AcceptsReturn="True"
                 ScrollViewer.VerticalScrollBarVisibility="Auto"
                 Background="#FF0d0d0d"
                 Foreground="White"
                 BorderBrush="#FF282828"
                 BorderThickness="0,1,0,0">
    </RichTextBox>
</Grid>

我做错了什么?

【问题讨论】:

标签: c# wpf xaml


【解决方案1】:

根据Rich TextBox Class reference in MSDN,它没有对 SelectionStart、TextLength、SelectionLength、SelectionColor 和 ForeColor 的定义。

所以我建议你使用普通的 TextBox(See MSDN reference) 来使用 SelectioNStartSelectionLengthForeground 等功能,或者创建一个从 TextBox 类派生的自定义控件来实现所需的外观或功能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-20
    • 1970-01-01
    • 2013-05-20
    • 2019-09-03
    相关资源
    最近更新 更多