locked
Changing the button background color in the event handler with c# RRS feed

  • Question

  • I don't get it.  The following code should work perfectly... in theory.  Why isn't it recognizing the color input?
    button1.Background = new SolidColorBrush(Windows.UI.Color.Red);

    Friday, August 30, 2013 11:22 PM

Answers

  • Other than there not being a Color.Red (did you mean Colors.Red?) that works for me. (And other than hardcoding colors, but this is just test code. In production you'd pull the color from a resource and respect high contrast settings).

    Can you provide more context? Do you have the button template or contented so that the background isn't visible?

    --Rob

    • Marked as answer by RandyPete Saturday, August 31, 2013 2:45 PM
    Friday, August 30, 2013 11:33 PM
    Moderator
  • Hello huge_newbie,

    You can change your code:

    button1.Background = new SolidColorBrush(Windows.UI.Colors.Red);


    • Marked as answer by RandyPete Saturday, August 31, 2013 2:45 PM
    Saturday, August 31, 2013 4:15 AM

All replies

  • Other than there not being a Color.Red (did you mean Colors.Red?) that works for me. (And other than hardcoding colors, but this is just test code. In production you'd pull the color from a resource and respect high contrast settings).

    Can you provide more context? Do you have the button template or contented so that the background isn't visible?

    --Rob

    • Marked as answer by RandyPete Saturday, August 31, 2013 2:45 PM
    Friday, August 30, 2013 11:33 PM
    Moderator
  • Hello huge_newbie,

    You can change your code:

    button1.Background = new SolidColorBrush(Windows.UI.Colors.Red);


    • Marked as answer by RandyPete Saturday, August 31, 2013 2:45 PM
    Saturday, August 31, 2013 4:15 AM
  • Talking about feeling silly.  Missing an "s"!  Thanks guys.
    Saturday, August 31, 2013 2:44 PM