【问题标题】:wpf style ellipse button Fill property Imagewpf 样式椭圆按钮填充属性图像
【发布时间】:2011-01-11 09:34:36
【问题描述】:

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

【问题讨论】:

    标签: wpf image button styles ellipse


    【解决方案1】:

    你可以在绑定中使用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>
    

    【讨论】:

    • 无效但响应椭圆内的点击事件
    • 对不起,你是对的。 With...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多