0

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

我试过logUser.Foreground = Brushes.Black我在另一篇文章中读到的(如何在 Microsoft Expression Blend 4 中以编程方式更改标签的文本颜色),但它不起作用。

4

1 回答 1

2

Silverlight 没有 Brushes 类,因此会引发错误。

我浏览了 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);
于 2015-12-29T09:06:23.200 回答