2

我想将渐变属性绑定到按钮。我正在使用下面的代码。我能够绑定样式。你能建议我应该如何绑定 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>
4

2 回答 2

4

只需将其添加为buttonStyleGradient属性:buttonStyleBackground

<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>

如果您不想将其添加到样式中,则可以像这样手动放入按钮:

<Button  Style="{StaticResource buttonStyle}" Background="{StaticResource buttonStyleGradient}" >
于 2013-03-12T08:27:31.490 回答
2

您需要一个属性来应用渐变,尝试背景:

<Setter Property="Background" Value="{StaticResource buttonStyleGradient}"/>
于 2013-03-12T08:27:10.037 回答