Sri
Sri

Reputation: 177

How to set a background for a button with a specific style programatically in wp7?

I want to do the below settings in code for a button.

<Button.Background>
   <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
     <GradientStop Color="DarkSlateGray" Offset="0" />
     <GradientStop Color="White" Offset="1" />
  </LinearGradientBrush>
</Button.Background>

Does anyone know how to do this?

Upvotes: 0

Views: 477

Answers (1)

vcsjones
vcsjones

Reputation: 141588

Probably something like this:

var brush = new LinearGradientBrush {EndPoint = new Point(0.5, 1), StartPoint = new Point(0.5, 0)};
brush.GradientStops.Add(new GradientStop {Color = Color.FromArgb(0xFF, 0x2F, 0x4F, 0x4F), Offset = 0});
brush.GradientStops.Add(new GradientStop {Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), Offset = 1});
TheButton.Background = brush;

Upvotes: 1

Related Questions