1

您好我正在尝试使用图像创建 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}"/> 
4

1 回答 1

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>
于 2011-01-11T10:24:54.397 回答