0

如何根据运行时的值更改 XAML 文本框的背景颜色?这些颜色值可以由最终用户自定义。似乎我不能只设置“背景”属性。

    <TextBox Name="nameInput" Width="300" HorizontalAlignment="Left" />

后面的代码将如何实现这一点?这不起作用:

Private Sub NameInput_TextChanged(sender As Object, e As TextChangedEventArgs) Handles nameInput.TextChanged

    Select Case nameInput.Text
        Case "x"
            nameInput.Background = "Red"
        Case "y"
            nameInput.Background = "Green"
    End Select
End Sub
4

1 回答 1

1

您需要分配SolidColorBrush而不仅仅是Color.

Private Sub NameInput_TextChanged(sender As Object, e As TextChangedEventArgs) Handles nameInput.TextChanged

Select Case nameInput.Text
    Case "x"
        nameInput.Background = new SolidColorBrush(Windows.UI.Colors.Red);
    Case "y"
        nameInput.Background = new SolidColorBrush(Windows.UI.Colors.Green);
End Select
End Sub
于 2012-10-30T06:53:52.227 回答