views:

68

answers:

3

IN WPF,I can set the background of a stack panel using the below code

  stackPanelFlasher .Background =Brushes.Aqua 

How can i set the color as a hex color code (ex :#C7DFFC) ?

+1  A: 
stackPanelFlasher.Background = new SolidColorBrush(Color.FromArgb(alpha, reg, green, blue));
Thomas Levesque
+3  A: 

I think this sample helps you for xaml solution;

 <Border.Background>
       <LinearGradientBrush EndPoint="1.204,0.5" StartPoint="0.056,0.5">
           <GradientStop Color="#FFFFFFFF" Offset="0" />
           <GradientStop Color="#FFD4D7DB" Offset="1" />
       </LinearGradientBrush>                     
  </Border.Background>
NetSide
+4  A: 
BrushConverter bc = new BrushConverter();  
stackPanelFlasher.Background=  (Brush)bc.ConvertFrom("#C7DFFC"); 

Should do the job. If you want to make it waterproof, better would be

BrushConverter bc = new BrushConverter();  
Brush brush=(Brush)bc.ConvertFrom("#C7DFFC"); 
brush.Freeze();
stackPanelFlasher .Background=  brush;

needs less resources...

HCL