【问题标题】:Getting text color from Silverlight RichTextBox从 Silverlight RichTextBox 获取文本颜色
【发布时间】:2011-07-11 02:03:12
【问题描述】:

我在获取 RichTextBox 的文本颜色时遇到问题。有一种方法,但我失败了。帮助我使用这种方法,或者有什么方法可以做到这一点。 这是方法

run.Foreground(DependencyProperty)

【问题讨论】:

    标签: silverlight richtextbox


    【解决方案1】:

    我不确定该方法应该做什么,但在 XAML 中你会使用:

    <RichTextBox Name="MyBox" Text="Some text" Foreground="Red" />
    

    或者您可以将其绑定到 Brush 属性:

    <RichTextBox Name="MyBox" Text="Some text" Foreground="{Binding myColor}" />
    

    如果您尝试从后面的代码中设置它:

    Brush myBrush = new SolidColorBrush(Color.Red);
    MyBox.Foreground = myBrush;
    

    【讨论】:

      【解决方案2】:

      我只是找到了我的问题的答案

      ((System.Windows.Media.SolidColorBrush)(run.Foreground)).Color.ToString()
      

      使用上面的代码,我可以得到十六进制文本的颜色。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-11
        相关资源
        最近更新 更多