Two buttons:
<Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="10,10,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
<Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="10,92,0,0" Name="button2" VerticalAlignment="Top" Width="160" />
Self explanatory code:
public MainPage()
{
InitializeComponent();
button1.Background = new SolidColorBrush(Colors.Red);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Color c = ((SolidColorBrush)((Button)sender).Background).Color;
if (c == Colors.Red)
{
c = Colors.Green;
}
else if (c == Colors.Green)
{
c = Colors.Blue;
}
else if (c == Colors.Blue)
{
c = Colors.Red;
}
else
{
c = Colors.Yellow;
}
((Button)sender).Background = new SolidColorBrush(c);
button2.Background = new SolidColorBrush(c);
}
In an ordinary Silverlight app everthing works exactly as expected. However, in Windows Phone 7 the exact same code behaves as follows:
button1 does not change color (it just stays red)
button2 does change color unless I click it in which case it no longer changes color when I click button1 (i.e. its color is now stuck as well)
clue enyone?
Following should do the trick: