First test of a Windows Phone application

Posted by Maurizio Reginelli on Stack Overflow See other posts from Stack Overflow or by Maurizio Reginelli
Published on 2010-06-11T20:12:28Z Indexed on 2010/06/11 20:23 UTC
Read the original article Hit count: 256

Filed under:
|
|

I downloaded the Microsoft Visual Studio 2010 Express for Windows Phone and I wrote a simple application to make a first test of the emulator. In this application I have only a button with the property Content binded to a string called ButtonText and with the property Background binded to a SolidColorBrush named FillColor. I handled the Click event with this code:

    void MyButton_Click(object sender, RoutedEventArgs e)
    {
        if (toggle == true)
        {
            ButtonText = "Blue";
            FillColor = new SolidColorBrush(Colors.Blue);
        }
        else
        {
            ButtonText = "Red";
            FillColor = new SolidColorBrush(Colors.Red);
        }
        toggle = !toggle;
    }

Unfortunately this doesn't work. While the Content of the Button changes each time the button is pressed, I cannot say the same for the Background which remains at the same color.
Could you tell me what is wrong? Thank you.

I also post the XAML:

    <Grid x:Name="ContentGrid" Grid.Row="1">
        <Button Name="MyButton" Width="300" Height="300"
                Content="{Binding Path=ButtonText}" 
                Background="{Binding Path=FillColor}" />
    </Grid>

© Stack Overflow or respective owner

Related posts about c#

Related posts about Silverlight