日期:2014-05-18  浏览次数:21056 次

WPF如何在style中添加trigger?改变圆形按钮的背景色
大家请看我的代码 我做了一个圆形按钮,有渐变效果
现在的效果是一个红色按钮,上面的文字在鼠标移动到的时候会变成红色
这个很好做,因为只要改Foreground就可以了
现在我想改变圆形按钮的Fill Stroke等等特性,请问应该怎么做?
我自己试着的是 不能直接写Fill 写Ellipse.Fill也不对
不知道这个trigger应该写在什么位置?
希望高人给予解答~



XML code

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="Button" x:Key="foxbutton">          
        <Setter Property="Background" Value="Green"/>
    </Style>
    <Style x:Key="EllipseButton" TargetType="{x:Type Button}">
        <Setter Property="Height" Value="100"/>
        <Setter Property="Width" Value="100"/>
        <Setter Property="Template">            
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid>
                        <Ellipse>
                            <Ellipse.Effect>
                                <BlurEffect Radius="23"/>
                            </Ellipse.Effect>
                            <Ellipse.Fill>
                                <RadialGradientBrush>
                                    <GradientStop Color="#FFEB1C1C" Offset="0"/>
                                    <GradientStop Color="#B2DA3361" Offset="1"/>
                                </RadialGradientBrush>                            
                            </Ellipse.Fill>
                            <Ellipse.Stroke>
                                <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                                    <GradientStop Color="#FFC6EF18" Offset="0"/>
                                    <GradientStop Color="#FFDA1F97" Offset="1"/>
                                </LinearGradientBrush>
                            </Ellipse.Stroke>
                        </Ellipse>
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>            
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Foreground" Value="Red"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>



------解决方案--------------------
<Setter TargetName="" />
笔误了
------解决方案--------------------
探讨
引用:

<Setter TargetName="" />
笔误了


谢谢大神的指导,可是还是不太对 。。。。。
麻烦您再看看。

无法在 Style Setter 上设置 TargetName 属性。 行 37 位置 25.