WPF 与 Button 绑定线性渐变属性

Mav*_*ick 2 wpf wpf-4.0

我想将渐变属性绑定到按钮。我正在使用下面的代码。我能够绑定样式。你能建议我应该如何绑定linergradientbrush属性吗?

 <Window.Resources>
    <ResourceDictionary>
        <LinearGradientBrush x:Key="buttonStyleGradient"  EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="White" Offset="0" />
            <GradientStop Color="#FFACC3F5" Offset="1" />
        </LinearGradientBrush>
       <Style x:Key="buttonStyle" TargetType="Button">
           <Setter Property="FontFamily" Value="Vrinda"/>
          <Setter Property="FontSize" Value="24"/>
          <Setter Property="Padding" Value="8,4" />
          <Setter Property="Margin" Value="0" />
       </Style>
    </ResourceDictionary>
</Window.Resources><Button  Style="{StaticResource buttonStyle}" >                  
                <Label>Home</Label>
            </Button>
Run Code Online (Sandbox Code Playgroud)

Bla*_*hma 5

只需将其buttonStyleGradient作为buttonStyle属性添加到Background

<Style x:Key="buttonStyle" TargetType="Button">
  <Setter Property="FontFamily" Value="Vrinda"/>
  <Setter Property="FontSize" Value="24"/>
  <Setter Property="Padding" Value="8,4" />
  <Setter Property="Margin" Value="0" />
  <Setter Property="Background" Value="{StaticResource buttonStyleGradient}" />
</Style>
Run Code Online (Sandbox Code Playgroud)

如果您不想将其添加到样式中,您可以手动将其添加到按钮上,如下所示:

<Button  Style="{StaticResource buttonStyle}" Background="{StaticResource buttonStyleGradient}" >
Run Code Online (Sandbox Code Playgroud)