Кнопка эллипса в стиле wpf Свойство Fill Image - PullRequest
1 голос
/ 11 января 2011

Hello Я пытаюсь создать стиль 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 было переменным и устанавливалось атрибутом Content для Button. Я буду искать Binding, RelativeSource и т. Д. ... но был бы признателен, если у кого-то есть идеи, как этого добиться

Спасибо

Добавление

Что-то вроде

<Ellipse Fill="{TemplateBinding Content}"/> 

1 Ответ

2 голосов
/ 11 января 2011

Вы можете использовать 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>
...