Windows应用商店Visual Basic将前景设置为RGB / aRGB值

时间:2012-10-28 05:29:59

标签: vb.net xaml windows-8 windows-store-apps

我正在尝试使用Windows应用商店中的Visual Basic在运行时更改文本块的前景色。但是,我不知道这样做的正确方法。请协助。

我写的是:

TextBlock1.Foreground = Windows.UI.Colors.Red

它说“类型'Windows.UI.Color'的值无法转换为'Windows.UI.Xaml.Media.Brush'。”

我试过这些:

TextBlock1.Foreground = "Red"
TextBlock1.Foreground = "#FFC8C8C8"
TextBlock1.Foreground = &HFF0000FF&
TextBlock1.Foreground = &H0000FF&

我想我显然错过了正确的方法。任何帮助表示赞赏。 (:

1 个答案:

答案 0 :(得分:1)

您需要为其分配SolidColorBrush而不是Color

Dim redBrush As New SolidColorBrush
redBrush.Color = Windows.UI.Colors.Red
TextBlock1.Foreground = redBrush