Question

I'm studying developing apps for window phone 8.1. And i have a problem when i try to change background color of a button. In Mainpage.xaml, i have following code:

<Button 
    Name="button" Background="Pink" 
    Click="OnClick">
    ClickMe1
 </Button>

Then i define OnClick event:`

 private void ClickMe_Click(object sender, RoutedEventArgs e)
{
   button.Background = new SolidColorBrush(Colors.Green);
}

but it didn't work because: The name 'Colors' does not exsit in the current context I tried to fix

void OnClick(object sender, RoutedEventArgs e)
{
    button.Background = Brushes.Green;
}

but it didn't work :(

Was it helpful?

Solution

In Windows Phone 8.1, Colors class is in Windows.UI namespace.

So you can set background of button like this:

button.Background = new SolidColorBrush(Windows.UI.Colors.Red);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top