我想将gradient属性绑定到按钮。我正在使用下面的代码。我能够绑定风格。你能建议我如何绑定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>
答案 0 :(得分:4)
只需将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>
如果你不想将它添加到样式中,你可以像这样手动输入按钮:
<Button Style="{StaticResource buttonStyle}" Background="{StaticResource buttonStyleGradient}" >
答案 1 :(得分:2)
您需要一个属性来应用渐变,尝试背景:
<Setter Property="Background" Value="{StaticResource buttonStyleGradient}"/>