如何在wp 7中以编程方式为具有特定样式的按钮设置背景?

时间:2011-12-14 22:25:10

标签: windows-phone-7 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>

有谁知道怎么做?

1 个答案:

答案 0 :(得分:1)

可能是这样的:

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;