locked
Set background color of rectangle programatically RRS feed

  • Question

  • Hi, 

    How can I set the background color of a rectangle programatically in c#?

    XAML:

    <Rectangle x:Name="MyAnimatedRectangle" Fill="#FF0086FF" StrokeThickness="0"/>

     

    I've tried to add a property, but this doesn't work :-(

    C#:

    Color glowColor = Color.FromArgb(0,33,99,0);
    SetValue(BackgroundProperty, glowColor);

     
    ......
    Monday, October 27, 2008 6:55 AM

Answers

  • To change the background of an rectangle you need to set it's fill property to a brush of the color you want the background to be 

     

    myRect.Fill = new SolidColorBrush(Colors.Red);

     

    Monday, October 27, 2008 7:05 AM

All replies

  • To change the background of an rectangle you need to set it's fill property to a brush of the color you want the background to be 

     

    myRect.Fill = new SolidColorBrush(Colors.Red);

     

    Monday, October 27, 2008 7:05 AM
  •  Smile that works, tanks a lot !

    Monday, October 27, 2008 7:59 AM