如何在 Microsoft Expression Blend 4 中更改 C# 中文本框的前景色?

How do you change foreground color of a textBox in C# in Microsoft Expression Blend 4?

这是我第一次使用 Microfoft Expression Blend。我的项目是 Silverlight Prototype(sketchflow)。 我有一个 TextBox(TextBox = logUser),我想更改它的前景色。

我尝试了 logUser.Foreground = Brushes.Black,我在另一个 post(How do you change the text colour of a label programmatically in Microsoft Expression Blend 4) 中阅读了它,但它不起作用。

Silverlight 没有画笔 class,因此会抛出一个错误。

我查看了 System.Windows.Media 的定义,了解到它为您提供了一个继承自 Brush

SolidColorBrush
#region Assembly System.Windows.dll, v2.0.50727
using System.Windows;
using System.Windows.Markup;

namespace System.Windows.Media
{
    // Summary:
    //     Paints an area with a solid color.
    [ContentProperty("Color", true)]
    public sealed class SolidColorBrush : Brush
    {
        // Summary:
        //     Identifies the System.Windows.Media.SolidColorBrush.Color dependency property.
        //
        // Returns:
        //     The identifier for the System.Windows.Media.SolidColorBrush.Color dependency
        //     property.
        public static readonly DependencyProperty ColorProperty;

        // Summary:
        //     Initializes a new instance of the System.Windows.Media.SolidColorBrush class
        //     with no color.
        public SolidColorBrush();
        //
        // Summary:
        //     Initializes a new instance of the System.Windows.Media.SolidColorBrush class
        //     with the specified System.Windows.Media.Color.
        //
        // Parameters:
        //   color:
        //     The color to apply to the brush.
        public SolidColorBrush(Color color);

        // Summary:
        //     Gets or sets the color of this System.Windows.Media.SolidColorBrush.
        //
        // Returns:
        //     The brush's color. The default value is System.Windows.Media.Colors.Transparent.
        public Color Color { get; set; }
    }
}

因此,要实现您的目标,您必须像下面这样使用 SolidColorBrush :

logUser.Foreground = new SolidColorBrush(Colors.Black);