Question : Silverlight Button Coloring in Code

When I change color of Button at runtime to Red, it does not appear solid bright Red.
I use following code.
          newBtn = new Button();
          newBtn.Margin = new Thickness(7,3,7,3);
          newBtn.Background = new SolidColorBrush(Colors.Red);
          newBtn.Content = "Done";
How can I get solid Red color in the Button?  I do not care if Button is not in 3D style.  To see what I am talking about, use above code to create a Button and Run application to see it in the Browser.

Thanks,
Ashok

Answer : Silverlight Button Coloring in Code

There are a few ways to do this as shown in the code below.

If you're using this button all over the place the best way is to modify the button control itself as described by ViNull here: http://stackoverflow.com/questions/442722/silverlight-button-color-hardly-changes-when-setting-background-property
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
//Type #1: button with solid red background
Button btn = new Button();
Border red = new Border();
TextBlock text = new TextBlock();
 
text.Text = "runtime Button";
red.Background = new SolidColorBrush(Colors.Red);
red.Child = text;
btn.Content = red;
LayoutRoot.Children.Add(btn);
 
//Type #2: button with some gradient effects of the button showing through
Button btn = new Button();
Grid grd = new Grid();
Border red = new Border();
TextBlock text = new TextBlock();
 
text.Text = "runtime Button";
red.Background = new SolidColorBrush(Colors.Red);
red.Opacity = 0.7;
grd.Children.Add(red);
grd.Children.Add(text);
btn.Content = grd;
LayoutRoot.Children.Add(btn);
Random Solutions  
 
programming4us programming4us