您好 我正在尝试使用图像创建RadialButton样式,我希望该图像(源)可变。
<Style x:Key="RadialButton1" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Ellipse
Stroke="Black"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="60"
Height="60"
x:Name="Ellipse" >
<Ellipse.Fill >
<ImageBrush ImageSource="/DessCol;component/Images/Recommencer.ico"/>
</Ellipse.Fill>
</Ellipse>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
...
<Button Height="37" HorizontalAlignment="Left" Margin="15,20,0,0" Name="btnRecommencer" VerticalAlignment="Top" Width="51" Style="{StaticResource RadialButton1}" Click="btnRecommencer_Click"/>
我希望Ellipse.Fill属性是可变的,并由Button的Content属性设置。 我会期待Binding,RelativeSource等...但如果有人知道如何实现这一点,我将不胜感激
谢谢
附录
像
这样的东西<Ellipse Fill="{TemplateBinding Content}"/>
答案 0 :(得分:2)
您可以在Binding
中使用RelativeSource<Style x:Key="RadialButton1" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Ellipse Stroke="Black" HorizontalAlignment="Center" VerticalAlignment="Center"
Width="60" Height="60" x:Name="Ellipse" >
<Ellipse.Fill >
<ImageBrush ImageSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}},
Path=Content}"/>
</Ellipse.Fill>
</Ellipse>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>