Search code examples
c#xamlwindows-phone-8-sdk

How do I change foreground color of a button when clicked?


I have something like this:

                        <Grid>
                            <StackPanel Margin="100,0,98,0">
                                <Button x:Name="BtProd"
                                   Content="{Binding Produto}"     
                                   FontSize="{StaticResource PhoneFontSizeLarge}"
                                   Foreground="{Binding Color}"
                                   Click="BtProd_Click">
                                </Button>
                            </StackPanel>
                        </Grid>

How do I change the text color of a button in the C# .cs file?

   private void BtProd_Click(object sender, RoutedEventArgs e)
    {
    ?
    }

I'd like to change from white to lightgray when user clicks the button. Thank You.


Solution

  • (sender as Button).Foreground = new SolidColorBrush(Colors.LightGray);